Problem Description
Given an integer
n
, we only want to know the sum of 1/k2 where
k
from 1 to
n
.
Input
There are multiple cases.
For each test case, there is a single line, containing a single positive integern .
The input file is at most 1M.
For each test case, there is a single line, containing a single positive integer
The input file is at most 1M.
Output
The required sum, rounded to the fifth digits after the decimal point.
Sample Input
1 2 4 8 15
Sample Output
1.00000 1.25000 1.42361 1.52742 1.58044
题目大意:
给你一个数
n
,让你求
解题思路:
这个式子,当
n
足够大的时候,这个式子趋近于
/**
2016 - 09 - 18 下午
Author: ITAK
Motto:
今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e6+5;
const int MOD = 1e9+7;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
LL Scan_LL()///输入外挂
{
LL res=0,ch,flag=0;
if((ch=getchar())=='-')
flag=1;
else if(ch>='0'&&ch<='9')
res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')
res=res*10+ch-'0';
return flag?-res:res;
}
int Scan_Int()///输入外挂
{
int res=0,ch,flag=0;
if((ch=getchar())=='-')
flag=1;
else if(ch>='0'&&ch<='9')
res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')
res=res*10+ch-'0';
return flag?-res:res;
}
void Out(LL a)///输出外挂
{
if(a>9)
Out(a/10);
putchar(a%10+'0');
}
char str[MAXN];
int main()
{
while(~scanf("%s",str))
{
int len = strlen(str);
if(len >= 7)
{
puts("1.64493");
continue;
}
int sum = 0;
for(int i=0; i<len; i++)
sum = sum*10 + (str[i] - '0');
if(sum >= 120000)
{
puts("1.64493");
continue;
}
double ans = 0.0;
for(double i=1; i<=sum; i++)
ans += 1.0/(i*i);
printf("%.5lf\n",ans);
}
return 0;
}