0分满江黑求助!

P1035 [NOIP2002 普及组] 级数求和

__Harry_Haiyun__ @ 2023-05-10 13:15:54


#include <iostream>
using namespace std;
int main()
{
    int k;
    cin >> k;
    int sum = 0,n = 0;
    float i = 1;
    while (sum < k)
    {
        sum += i;
        sum = sum;
        n++;
        i /= 2;
    }
    cout << n;
    return 0;
} 

by _buzhidao_ @ 2023-05-10 13:17:22

@Harry_Haiyun 死循环了

#include<bits/stdc++.h>
using namespace std;
int k,n;double deshu;
int main(){
    cin>>k;
    while(deshu<=k){
        n+=1;
        deshu+=1.0/n;
    }
    cout<<n;
    return 0;
}

by _buzhidao_ @ 2023-05-10 13:18:57

@Harry_Haiyun i/=2.0


by jyhDora2011 @ 2023-05-21 16:45:45

sum应该是个double类型的数


|