題目來源:https://zerojudge.tw/ShowProblem?problemid=d356
已知:Sn= 1+1/2+1/3+…+1/n,求給定任意K直,找出SN>K時,N為何
範例輸入
1
範例輸出
2
簡易程式碼如下:
#include <iostream>
using namespace std;
int main() {
cin.tie(0),cin.sync_with_stdio(0);
double b = 1,c = 1,a = 1;
cin >> a;
while(b <= a) {
c+=1;
b += 1/c;
}
cout << c << "\n";
}
沒有留言:
張貼留言