CQU5S @ 2021-02-05 13:10:32
#include<bits/stdc++.h>
using namespace std;
int main(){
double m=0,n,k;
cin>>k;
for(n=1;m<k;n++){
m=m+(1/n);
}
cout<<n;
return 0;
}
by CQU5S @ 2021-02-05 13:38:26
#include<bits/stdc++.h>
using namespace std;
int main(){
double m=0.0;
int n,k;
cin>>k;
for(n=1;m<=k;n++){
m=m+(1.0/n);
}
cout<<n;
return 0;
}
WA
by CQU5S @ 2021-02-05 13:39:42
我崩了
by CQU5S @ 2021-02-05 13:43:37
#include<bits/stdc++.h>
using namespace std;
int main(){
double m=0.0;
int n=1,k;
cin>>k;
for(n=1;m<=k;n++){
m=m+(1.0/n);
}
cout<<n-1;
return 0;
}
AC了
by 追梦之鲸 @ 2021-02-05 14:01:06
az……
by lyhqwq @ 2021-02-05 16:02:00
#include<iostream>
using namespace std;
int main(){
double a=1,sum=0,k;
cin>>k;
int i;
for(i=1;sum<=k;i++){
sum=sum+1.0*1/i;
}
cout<<i-1<<endl;
return 0;
}
by wanxdy @ 2021-02-06 15:07:15
#include <bits/stdc++.h>
using namespace std;
int main()
{
int k, n = 0;
double sn = 0;
cin >> k;
while(sn <= k)
{
n++;
sn += 1.0 / n;
}
cout << n << endl;
return 0;
}
by Otomachi_Una_ @ 2021-02-09 17:43:37
精度不够,改成这样就好了
#include<bits/stdc++.h>
using namespace std;
int main(){
double m=0.000000,n,k;
cin>>k;
for(n=1;m<k;n++){
m=m+(1.000000/n);
}
cout<<n-1;
return 0;
}
by Gold14526 @ 2021-05-06 19:18:45
题目中说的是S>k你这里如果S=k也退出了,以后要认真读题
by zhou_zijie @ 2021-05-13 20:04:43
#include<bits/stdc++.h>//万能头文件
using namespace std;
int main ()
{
int n=1,k; //定义整形变量n,k。
double tmp=0.0000;
cin>>k;//输入
while(tmp<=k)//精度不可少哦
{
tmp+=1.0/n;
n++;
}
cout<<n-1;//输出答案
return 0;//主过程返回值0.
}
by 淡泊芝士 @ 2021-08-09 18:13:57
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int k,i=0;
double s=0.0000;//请注意精度
cin>>k;
do
{
i++;
s=s+ (1.0/i);//请注意除法两边数据类型(不能使是int,不然等于div运算)
} while (s<=k);
printf("%d",i);
return 0;
}