Aa123456 @ 2015-06-21 21:38:44
/*已知:Sn= 1+1/2+1/3+…+1/n。显然对于任意一个整数K,
当n足够大的时候,Sn大于K。现给出一个整数K(1<=k<=15),
要求计算出一个最小的n;使得Sn>K*/
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
double sn=1.0;
double n=0.0;
int k;
scanf("%d",&k);
for(n=2.0;;n+=1.0)
{
sn+=1.0/n;
if(sn>k)
break;
}
printf("%d",n/1);
}
by Ufowoqqqo @ 2015-06-22 14:39:05
[codec]
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int k;
double S=0,n=0;
scanf("%d",&k);
while(S<=k)
S+=1/++n;
printf("%.0f\n",n);
return 0;
}
[/codec]