Cure
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 293 Accepted Submission(s): 96
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
n没有给出范围,意思就是默认无限大。。。。。比赛时被坑了,不停RE。
1 //2016.9.17 2 #include <iostream> 3 #include <cstdio> 4 5 using namespace std; 6 7 double sum[54000]; 8 9 int main() 10 { 11 int n; 12 double ans; 13 ans = 0; 14 sum[0] = 0; 15 for(int i = 1; i <= 53000; i++) 16 { 17 ans += (1.0/i)*(1.0/i); 18 sum[i] = ans; 19 } 20 string s; 21 while(cin>>s) 22 { 23 int len = s.length(); 24 n = 0; 25 for(int i = 0; i < len; i++) 26 { 27 n = n*10+s[i]-'0'; 28 if(n > 120000)break; 29 } 30 if(n >= 110291)ans = 1.64493; 31 else if(n >= 52447)ans = 1.64492; 32 else ans = sum[n]; 33 printf("%.5lf ", ans); 34 } 35 36 return 0; 37 }