ztojojo @ 2024-07-07 11:15:42
#include<iostream>
using namespace std;
int main()
{
float Sn=0,n=1,i,k;
cin>>k;
for(i=1;i<=k;i++){
Sn=Sn+(float)1/i;
}
while(n<=Sn){
n=n+1;
}
cout<<n;
return 0;
}
by Ivan422 @ 2024-07-07 11:38:59
精度问题,开 double
可以关注下吗
by ztojojo @ 2024-07-07 11:47:10
@Ivan422 用了double还是全红怎么办qwq
by ztojojo @ 2024-07-07 11:47:34
@Ivan422 已关注大佬
by Ivan422 @ 2024-07-07 11:57:39
@ztojojo
Um, 我给你点数据吧,你看看怎么错的。
by Ivan422 @ 2024-07-07 11:58:56
@ztojojo
5 输出 83
10 输出 12367
15 输出 1835421
by jiangyichen_10 @ 2024-07-11 12:03:07
```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
double n=1,s=0,k;
cin>>k;
while(s<=k){
s=s+(1/n);
n++;
}
ll t=n-1;
cout<<t<<endl;
return 0;
}
```
放心,已AC。
by jiangyichen_10 @ 2024-07-18 13:52:01
求关
by eggs_party @ 2024-07-24 15:52:47
#include<bits/stdc++.h>
using namespace std;
double Sn,i,k,cnt;
int main(){
cin>>k;
for(i=1;;i++){
cnt++;
Sn+=1.0/i;
if(Sn>k){
break;
}
}
cout<<cnt;
return 0;
}