这么一道简单的题,我怎么可能会写n方呢

题目

using namespace std;
inline int read(){
	register int x=0,t=1;
	register char ch=getchar();
	while(!isdigit(ch)){t=ch=='-'?-t:t;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*t;
}
signed main(){
	int n=read();
	double ans=0;
	for(register int i=1;i<=n;i++)
		ans+=1.0/((i%2*2-1)*(i));//公式
	cout<<fixed<<setprecision(3)<<ans<<endl;
	return 0;
}