微长

P1035 [NOIP2002 普及组] 级数求和

tees_of_times @ 2024-07-14 10:10:31

#include <iostream>
using namespace std;
int a(int k){
    int n=1;
    double b=0.0;

    while(true){
        b+=1.0/n;
        if (b>k){
            return n;
        }
        n++;
    }
}
int main(){
    int k;
    cin>>k;
    int c=a(k);
    cout<<c<<endl;
    return 0;
}

求改


by toolazy @ 2024-07-14 10:17:38

#include <iostream>
using namespace std;int a(int k){int n=1;double b=0;while(true){b+=1.0/n;if(b>k){return n;}n++;}}main(){int k;cin>>k;cout<<a(k)<<endl;return 0;}

by tees_of_times @ 2024-07-14 10:37:46

@_venti huh?


by toolazy @ 2024-07-14 10:50:42

#include<iostream>
using namespace std;int a(int k){int n=0;double b=0;while(true){b+=1.0/(++n);if(b>k)return n;}}main(){int k;cin>>k;cout<<a(k);}

by tees_of_times @ 2024-07-14 20:23:36

@_venti 6


by Hgvuryg27 @ 2024-07-20 08:18:17

@_venti 6,这么极限吗?压缩成两行


by Pig3 @ 2024-08-03 11:34:21

#include <iostream>
using namespace std;
int a(int k){
    int n=1;
    double b=0;
    while(true){
        b+=1.0/n;
        if (b>k){
            return n;
        }
        n++;
    }
}
int main(){
    int k;
    cin>>k;
    cout<<a(k)<<endl;
}

这是我的极限了……


|