题目描述 Description
输入一个数x(x <= 10000),求数n使的S= 1+1/2+1/3+…+1/n>=x的最小n值。但如果在n > 5000000时都无法满足,则输出“Error!”(没有引号)
输入描述 Input Description
只有一个数x
输出描述 Output Description
如果数n使的S= 1+1/2+1/3+…+1/n>=x的最小n值小于5000000,则输出一个数n
否则输出“Error!”(没有引号)
样例输入 Sample Input
输入样例1
10
输入样例2
1000
样例输出 Sample Output
输出样例1
12367
输出样例2
Error!
数据范围及提示 Data Size & Hint
详见试题
代码
#include <cstdio>
using namespace std;
int main(){
int x,n;
double s=0;
scanf("%d",&x);
for(n=1;n<=5000000;n++){
s+=1/n;
if(s>=x) break;
}
if(n>5000000) printf("Error!");
else printf("%d",n);
return 0;
}