1 条题解

  • 0
    @ 2022-12-9 0:58:45

    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的值。

    信息

    ID
    114
    时间
    1000ms
    内存
    16MiB
    难度
    9
    标签
    递交数
    9
    已通过
    9
    上传者