more_Power @ 2023-09-05 15:28:06
#include<iostream>
using namespace std;
double Sn(int x)
{
double sn = 0;
for (int i = 1; i <= x; i++)
sn += 1.0 / i;
return sn;
}
int main()
{
int k;
cin >> k;
long i;
for (i = 1; Sn(i) <= k; i++)
{
}
cout << i;
system("pause");
return 0;
}
by more_Power @ 2023-09-05 20:01:10
@VIOLET__FOREVER 悟了,非常感谢!!!
by more_Power @ 2023-09-05 20:03:47
@Most_High_Cold 是我傻了,根本没必要用什么函数,每调用一次,前面的数据都要再跑一次,根本没必要,确实边累加便判断的好。。。非常感谢!!!
by Andy_hpy @ 2023-09-13 15:06:18
#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;
}