- 级数求和
- 2016-11-09 21:45:54 @
我把int改成double把1/n改成1.0/n然后就过了!!!
2 条评论
-
Flokirie LV 8 @ 2017-01-19 17:40:55
当然是这样
-
2016-11-09 21:46:30@
评测结果 编译成功 测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #2: Accepted, time = 15 ms, mem = 560 KiB, score = 10 测试数据 #3: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10 Accepted, time = 15 ms, mem = 560 KiB, score = 50 代码 #include<iostream> using namespace std; int k,n=1; double ans=0; int main() { cin>>k; while(1) { ans+=1.0/n; if(ans>k) break; n++; } cout<<n; return 0; }
- 1