- 级数求和
#T1087. 级数求和,为什么用“1/n”会超时
- @ 2025-10-18 15:53:50
#include <bits/stdc++.h>
using namespace std;
int k, n = 1;
double s;
int main ()
{
cin >> k;
while ( s < k )
{
s += ( 1 / n );
n ++;
}
cout << n << '\n';
return 0;
}
1 comments
-
Csvoner SU @ 2025-10-22 18:23:55
你的
n, k都定义的整数,那级数求和的结果必定有小数,那循环的条件不就判错了吗?
- 1
Information
- ID
- 581
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- (None)
- # Submissions
- 401
- Accepted
- 146
- Uploaded By