xclyk @ 2022-07-12 22:10:46
#include<bits/stdc++.h>
using namespace std;
int k,n,i=1;
int main()
{
cin>>k;
n+=1;
while(k>n)
{
i++;
n+=(1/i);
}
cout<<i+1;
return 0;
}
by ppip @ 2022-07-12 22:12:12
将n换成double,1/i换成1.0/i。
by Joker_1212 @ 2022-07-12 22:12:47
@xclyk n
要用 double
,否则无限循环
by 金庆涵 @ 2022-07-12 22:13:32
开浮点数,因为整型1/i 当 i > 2 时恒为零, 所以一直加不完