超时怎么改...

P1035 [NOIP2002 普及组] 级数求和

小骁` @ 2019-11-03 14:53:07

include<stdio.h>

int main() { int a,b,sum,i; sum=0; scanf("%d",&a); for(i=1; sum<a; i++) { sum=sum+1/i; }

printf("%d",i);
return 0;

}


by Hydrate @ 2019-11-03 15:05:06

@胡子骁 使用浮点型即可AC.


by Hydrate @ 2019-11-03 15:07:22

#include<stdio.h> 
int main()
{
    int a,i; 
    float b,sum; 
    sum=0.0; 
    scanf("%d",&a);
    for(i=1; sum<a; i++)
    {
        sum=sum+1.0/i;
    }
    printf("%d",i);
    return 0;
}

@胡子骁


by tZEROちゃん @ 2019-11-03 15:08:22

i用double 1改成1.0


by 小骁` @ 2019-11-05 12:47:21

@北辰yama 谢啦


by 小骁` @ 2019-11-05 12:56:21

@北辰yama 五个wrong answer....


by MISSCCY @ 2019-11-09 22:11:22

请问楼主解答出来了吗?我的代码也超时,无法解决~


|