Cure
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 580 Accepted Submission(s): 206
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 integer n .
The input file is at most 1M.
For each test case, there is a single line, containing a single positive integer n .
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
Source
比赛的时候一直提示runtime error 原来输入是数组,诶,我这个小白被坑上面了。无奈。
代码附上啊:
#include <stdio.h>
#include <string.h>
double a[1000001]={0};
char b[1000005];
int main()
{
int i,j,len,n;
double sum,tmp;
for(i=1;i<=1000000;i++)
{
tmp=i*1.0;
a[i]=a[i-1]+(1.0)/(tmp*tmp);
}
while(~scanf("%s",b))
{
len=strlen(b);
n=0;
if(len>=7)
printf("%.5lf\n",a[1000000]);
else
{
for(j=0;j<len;j++)
{
n=n*10+b[j]-'0';
}
printf("%.5lf\n",a[n]);
}
}
return 0;
}