2016 ACM/ICPC Asia Regional Qingdao Online -Cure

来源:互联网 发布:前端如何优化代码 编辑:程序博客网 时间:2024/06/01 16:56

Problem Description
Given an integer n, we only want to know the sum of 1/k2where kfrom 1to 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

#include"stdio.h"#include"iostream"#include"string.h"#include"math.h"using namespace std;char n[1100000];double gg[150000];double he=0;long long  i;int main(){    int m;    double he=0;    for(i=1;i<=150000;i++){    he+=1.0/(i*i);    gg[i]=he;}    while(scanf("%s",n)==1)    {        he=0;        m=0;        if (strlen(n)>6)        {            printf("1.64493\n");            continue;        }        for (i=0; i<strlen(n); i++)        {            int n1 = pow(10,strlen(n)-i-1);            m+=(n[i]-48)*n1;        }        if(m>150000)        {            printf("1.64493\n");        }        else        {                printf("%.5lf\n",gg[m]);        }    }    return 0;}
0 0