1 solutions

  • 0
    @ 2025-3-3 16:33:59

    C++ :

    #include <iostream>  
    using namespace std;  
    int main(){  
        int i = 1,n,x;
        double s = 0;
        cin>>x;
         while(s <= x){ 
       s = s + 1.0 / i;
       i++;
    }
    cout<<i - 1<<endl;
        return 0;  
      } 
    
    

    Python :

    x = int(input())
    s = 0
    i = 1
    while True:
        s += 1 / i
        if s > x:
            print(i)
            break
        i += 1
    
    • 1

    【入门】求恰好使s=1+1/2+1/3+…+1/n的值大于X时n的值。

    Information

    ID
    10846
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By