链接:http://acm.hdu.edu.cn/showproblem.php?pid=5879
解法:我们知道到某个极限之后结果相同,所以找到那个极限,其他保存之后输出就好了
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define MAXN (100000+10)
#define MAXM (100000)
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
double a[1000000];
void cmd()
{
a[0]=0;
a[1]=1;
for(long long i=2; i<1000000; i++)
{
a[i]=a[i-1]+1.0/(i*i);
}
}
int main()
{
string s;
cmd();
while(cin>>s)
{
if(s.length()>=7)
{
printf("%.5f\n",a[1000000-1]);
}
else
{
int b=0;
for(int i=0; i<s.length(); i++)
{
b=b*10+s[i]-'0';
}
printf("%.5f\n",a[b]);
}
}
return 0;
}