求改进

P1035 [NOIP2002 普及组] 级数求和

The_joker @ 2017-10-02 15:56:00

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

by Captain_Paul @ 2017-10-02 16:20:45

存储总和的类型应该是double


|