首页 > 代码库 > 2016 ACM/ICPC Asia Regional Qingdao Online 1002 Cure
2016 ACM/ICPC Asia Regional Qingdao Online 1002 Cure
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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
n范围很大,需要用字符串读入
1 #include <iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstdlib> 5 #include<cstring> 6 using namespace std; 7 double a[1000005]; 8 char ch[1000005]; 9 int n;10 int main()11 {12 13 for(int i=1000000;i>=1;i--)14 a[i]=a[i+1]+1.0/pow((double)i,2.0);15 16 while(~scanf("%s",&ch))17 {18 int len=strlen(ch);19 int n=0;20 for(int i=0;i<len;i++) {n=n*10+ch[i]-‘0‘; if (n>1000000) break;}21 22 if(n>=1000000) printf("%.5lf\n",a[1]);23 else printf("%.5lf\n",a[1]-a[n+1]);24 }25 return 0;26 }
2016 ACM/ICPC Asia Regional Qingdao Online 1002 Cure
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。