2 条题解

  • 1
    @ 2022-9-28 15:40:20

    1

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

    2

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int k;
        double Sn, n;
        cin >> k;
        Sn = 0;
        n = 0;
        while (Sn <= k)
        {
            n += 1;
            Sn += 1 / n;
        }
        // 假设 x 是一个 float/double 型的小数
        // 常用 int(x)、(int)(x)、(int)x 的方式得到小数取整后的值
        // 也可以通过 int y = x; 的方式将取整后的值储存到变量 y 里
        cout << (int)n;
        return 0;
    }
    
    • 0
      @ 2023-6-26 16:46:37

      for循环

      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
      	int i,a;
      	double s=1;
      	cin>>a;
      	for(i=1;a>=s;i++,s+=(1.0/i));
      	cout<<i;	
      	return 0;
      }
      
      • 1

      信息

      ID
      307
      时间
      1000ms
      内存
      128MiB
      难度
      5
      标签
      (无)
      递交数
      249
      已通过
      96
      上传者