求助,WA了两个点

P1035 [NOIP2002 普及组] 级数求和

142857142857a @ 2023-11-20 21:13:21


#include<bits/stdc++.h>
using namespace std;
int main(){
    int k;
    float Sn=0,n=1;
    cin>>k;
    for(int i=1;i<=n;i++){
        Sn+=1/n;
        if(Sn>k){
            break; 
        }
        else n++;
    }
    cout<<n;
    return 0;
}

by L_MaJiaQi @ 2023-11-20 21:17:57

@142857142857a 用double


by 142857142857a @ 2023-11-20 21:21:46

@YC_George 谢谢


|