c++,编译提示超过时间,得分0???

P1035 [NOIP2002 普及组] 级数求和

FLOYD @ 2017-09-21 15:34:05

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

by FLOYD @ 2017-09-21 15:37:39

自己解决了。。。。SUM=SUM+(1.0/N)...(把原来的1/N改成1.0/N就OK)


by huangdejing @ 2017-09-21 19:16:51

为什么


|