您的位置:首页 > 其它

hdu 5879 -Cure 暴力打表

2016-09-17 18:21 357 查看
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
);
}

}
return 0;

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