Initiate Luogu
This commit is contained in:
18
Luogu/P1035 [NOIP2002 普及组] 级数求和.cpp
Normal file
18
Luogu/P1035 [NOIP2002 普及组] 级数求和.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
double sum; // Use double for sum to handle fractions
|
||||
int n, k;
|
||||
cin >> k;
|
||||
n = 1;
|
||||
sum = 0.0;
|
||||
while (sum <= k)
|
||||
{
|
||||
sum = sum + 1.0 / n; // Use 1.0 to ensure floating-point division
|
||||
n++;
|
||||
}
|
||||
cout << n - 1 << endl; // n is incremented one extra time in the loop
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user