您的位置:首页 > 其它

HDU 5879 Cure

2016-09-17 22:25 288 查看


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.

 

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

2016 ACM/ICPC Asia Regional Qingdao Online

比赛的时候一直提示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
);
}
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: