HDU 1012 u Calculate e【暴力打表,水】

简介: u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46844    Accepted Submission(s)...

u Calculate e

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 46844    Accepted Submission(s): 21489


Problem Description
A simple mathematical formula for e is



where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.
 

 

Output
Output the approximations of e generated by the above formula for the values of n from 0 to 9. The beginning of your output should appear similar to that shown below.
 

 

Sample Output
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
 

 

Source
分析:暴力打表就好了,因为数据范围只有10个,按照格式打出来就好了,一个简单的求阶层的题目!
下面给出AC代码:
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 inline double gcd(int n)
 4 {
 5     int sum=1;
 6     for(int i=1;i<=n;i++)
 7         sum*=i;
 8     return sum;
 9 }
10 int main()
11 {
12     cout<<'n'<<" "<<'e'<<endl;
13     cout<<"- -----------"<<endl;
14     cout<<0<<" "<<1<<endl;
15     cout<<1<<" "<<2<<endl;
16     cout<<2<<" "<<2.5<<endl;
17     double sum=2.5;
18     for(int i=3;i<=9;i++)
19     {
20         sum+=(1.0/(double)gcd(i));
21         printf("%d %.9lf\n",i,sum);
22     }
23     return 0;
24 }

 

目录
相关文章
|
6月前
|
算法
uva 11549 CALCULATOR CONUNDRUM
题目链接 刘汝佳算法竞赛经典入门训练指南p42
17 0
|
8月前
UVa11549 - Calculator Conundrum (Floyd判圈法)
UVa11549 - Calculator Conundrum (Floyd判圈法)
31 0
|
人工智能
CodeForces-Kuroni and Impossible Calculation(思维+鸽巢原理)
CodeForces-Kuroni and Impossible Calculation(思维+鸽巢原理)
63 0
HDU-1012,u Calculate e
HDU-1012,u Calculate e
|
人工智能
Kuroni and Impossible Calculation——容斥原理-鸽笼原理-抽屉原理
题目描述 已知一个数组a[n],请计算式子:∏_{1≤i<j≤n}|ai−aj| 的值,其中1<=i,j<=n;我们可以认为,这一式子等价于 |a1−a2|⋅|a1−a3|⋅ … ⋅|a1−an|⋅|a2−a3|⋅|a2−a4|⋅ … ⋅|a2−an|⋅ … ⋅|an−1−an|
91 0
Kuroni and Impossible Calculation——容斥原理-鸽笼原理-抽屉原理
|
C++
蓝桥杯 - C++ calculation
蓝桥杯 - C++ calculation
132 0
|
Java C语言
HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)
HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)
76 0
HDU-1001 calculate SUM(n) = 1 + 2 + 3 + ... + n.
HDU-1001 calculate SUM(n) = 1 + 2 + 3 + ... + n.

热门文章

最新文章