AFwhcing @ 2020-10-05 12:31:09
代码
#include<bits/stdc++.h>
using namespace std;
int main(){
int n=1,k;double s=0;
scanf("%d",&k);
for(;s<=k;++n) s+=1.0/n;
printf("%d",n);
return 0;
}
www,ZENMEGAODE?WTF?
by __LIHANSEN__ @ 2020-10-25 22:05:25
emm……lz对比一下我的吧
#include <iostream>
#include <cstdio>
using namespace std;
int K, N;
double Sum;
int main() {
// freopen("sum.in", "r", stdin);
// freopen("sum.out", "w", stdout);
cin >> K;
while(Sum <= K) {
N++;
Sum += 1.0 / N;
}
cout << N;
return 0;
}
by CCF_AK_ME @ 2021-05-28 17:19:51
特判2 if(n==2) cout<<2<<endl; cout<<n-1<<endl; 3应输出11 k=3; 1+1/2+1/3+1/4+...+1/11=3又551/27720
by CCF_AK_ME @ 2021-05-28 17:21:54
3
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
double s=0;
scanf("%d",&k);
for(n=1;s<=k;++n) s+=1.0/n;
if(n==2) cout<<n<<endl;
printf("%d\n",n-1);
return 0;
}