九头蛇 @ 2016-12-23 11:06:34
#include <iostream>
#include <stdio.h>
using namespace std;
int main( )
{
int k,n;
float m=0.00;
cin>>k;
for(n=1;n<=100000;n++)
{
m=m+1.0/n;
if(m>k) break;
}
printf("%d",n);
return 0;
}
by Hcf2002 @ 2016-12-23 12:32:16
换成while试试
by 郑王围霸 @ 2016-12-29 16:57:02
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int k;
double s=0;
cin >> k;
int i=0;
while (s <=k)
{
i++;
s +=1.0/i;
}
cout << i << endl;
return 0;
}
by woshihasong @ 2017-01-06 22:36:41
100000太小了,Sn>15 n=1835421
by zm不是猪你信吗 @ 2017-01-09 19:04:56
#include<iostream>
using namespace std;
int main()
{
double a,b=0;
cin>>a;
while(a>=0)
{
b++;
a-=1/b;
}
cout<<b;
return 0;
}