已知:S_n= 1+1/2+1/3+…+1/nSn=1+1/2+1/3+…+1/n。显然对于任意一个整数KK,当nn足够大的时候,S_nSn大于KK。
现给出一个整数KK(1 le k le 151≤k≤15),要求计算出一个最小的nn;使得S_n>KSn>K。
一个正整数KK
一个正整数NN
1
2
#include<bits/stdc++.h> using namespace std; int main(){ int k; cin>>k; double ans=0; int n=1; while(ans<=k){ ans+=1/double(n); ++n; } cout<<n-1; }