Cure---hdu5879(打表+找规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5879
题意:给你一个n ,求∑(1/k2), k from 1 to n;
n的范围是不知道的,所以可能很大;打表可以看出来当n大于10e6的时候值不变;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<queue> #include<set> using namespace std; #define met(a, b) memset(a, b, sizeof(a)) #define N 1000005 #define INF 0x3f3f3f3f typedef long long LL; const LL MAX = 1e9; double sum[N]; char str[N]; int main() { for(int i=1; i<N; i++) sum[i] = sum[i-1] + 1.0/(1.0*i*i); ///for(int i=50000; i<N; i++) /// printf("%d %.5f\n", N-1, sum[N-1]); while(scanf("%s", str) != EOF) { int len = strlen(str), num = 0; if(len > 6) { printf("1.64493\n"); continue; } for(int i=0; i<len; i++) num = num*10 + str[i]-'0'; if(num >= N) printf("1.64493\n"); else printf("%.5f\n", sum[num]); } return 0; }