zlh202483023 @ 2024-11-16 22:39:46
#include<iostream>
using namespace std;
int main() {
int k,n;
double sum;
n = 1;
sum = 0;
cin >> k;
while (k > sum) {
sum = sum +double( 1 / n);
n++;
}
cout << n;
return 0;
}
by Fractured_Angel @ 2024-11-16 22:58:28
全开 double 试试。
by zlh202483023 @ 2024-11-19 11:10:03
@Fractured_Angel全开double前几个变红WA了,之前是灰色TEL的
by mnblASEHEHEH @ 2024-11-24 19:56:23
试试下面的:
#include<bits/stdc++.h>
using namespace std;
int main(){
double k,n=0,sum=0,ii;
cin>>k;
for(int i=1;;i++) {
ii=i;
sum+=(1.0/ii);
if(sum>k){
n=i;
break;
}
}
cout<<n;
return 0;
}
我的过了