Given an integer n,
we only want to know the sum of 1/k2 where k from 1 to n
直接暴力1-1e6打表.
超过之后会收敛
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
double ans[1000000+5];
char ss[5000001];
int len;
int change(char *s)
{
int base=0,sum=0;
for (int i=0; i<len; i++)
{
sum=sum*10+s[i]-'0';
}
return sum;
}
int main()
{
//1.644934
// 1.644934;
for (int i=1; i<=1000000; i++)
{
ans[i]=ans[i-1]+1.0/i/i;
}
while(scanf("%s",ss)!=EOF)
{
len=strlen(ss);
if (len>6)
printf("1.64493\n");
else
{
int n= change(ss);
printf("%.5lf\n",ans[n]);
}
}
return 0;
}