求助,为什么TLE了?

P1035 [NOIP2002 普及组] 级数求和

louzhu @ 2023-03-11 13:22:51

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin >> k;
    int cnt = 0;
    double sum = 0;
    while(sum <= k)
    {
        cnt++;
        sum += 1 / cnt;
    }
    cout << cnt << endl;
    return 0; 
 } 

by Angel0418 @ 2023-03-11 13:28:55

@louzhu 复杂度


|