求助,0分

P1035 [NOIP2002 普及组] 级数求和

正式AFO @ 2017-03-10 22:14:52

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

by 正式AFO @ 2017-03-11 18:33:50

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

by 正式AFO @ 2017-03-11 18:34:39

AK


by lianglexuan2 @ 2017-03-19 10:36:44

#include<iostream>
using namespace std;
int k,c;
double v;
int main()
{
    cin>>k;v=0;c=0;
    while(v<=k)
     {
         c++;
         v=v+(1.0/c);
     }
    cout<<c;
    return 0;
}

|