lztz0503 @ 2023-08-28 13:04:52
#include <bits/stdc++.h>
using namespace std;
int n,cnt;
int i = 1;
int main(){
cin >> n;
while(n < cnt){
cnt += 1 / i;
i += 1;
}
cout << i;
return 0;
}
完全看不出代码哪里有问题的蒟蒻来讨论去求教了
题目传送门
by _Glassy_Sky_ @ 2023-08-28 13:26:35
@LuoJingjia 不是i+ 1吗?
by LittleAcbg @ 2023-08-28 13:32:49
@FZwangmuem 不是应该输出 i - 1
么
by Andy_hpy @ 2023-09-13 15:12:05
#include<bits/stdc++.h>
using namespace std;
int main(){
int k;
cin>>k;
double s=0;
long long n;
for(long long i=1;s<=k;i++){
s+=1.0/i;
n=i;
}
cout<<n;
return 0;
}