8 条题解

  • 3
    @ 2022-12-10 15:43:31

    AC代码,放心使用

    #include <iostream>
    using namespace std;
    int main()
    {
        int x, i = 1;
        float s = 0;
        cin >> x;
        while (s <= x)
        {
            s = s + 1.0 / i;
            i += 1;
        }
        cout << i - 1;
        return 0;
    }
    
    • 1
      @ 2023-7-30 21:09:29
      #include <iostream>
      using namespace std;
      int main()
      {
          int n, x = 1;
          float a = 0;
          cin >> n;
          while (a <= n)
          {
              a = a + 1.0 / x;
              x += 1;
          }
          cout << x - 1;
          return 0;
      }
      
      • 0
        @ 2024-6-4 21:42:35
        #include <iostream> 
        #include <iomanip>
         using namespace std; 
        int main(){ 	
            int i=0,x; 	
            cin>>x; 
            double sum=0; 	
            while(sum<=x){ 		
                i++; 		
                sum=sum+1.0/i; 	
            } 	
            cout<<i; 	
            return 0; 
        }
        
        • 0
          @ 2024-5-8 21:49:03
          #include <bits/stdc++.h>
          using namespace std;
          int x;
          int n=1;
          double sum;
          int main(){
          	cin>>x;
          	while (true){
          		sum+=(double)1/n;
          		if (sum>x){
          			cout<<n;
          			return 0; 
          		}
          		n++;
          	}
          	return 0;
          }
          
          • 0
            @ 2024-5-8 21:48:52
            
            
            • 0
              @ 2023-10-5 23:32:57
              #include<bits/stdc++.h>
              using namespace std;
              double x,m,sum;
              int main()
              {
                  cin>>x;
                  m=1;
                  while(sum<=x)
                  {
                      sum+=1/m;
                      m++;
                  }
                  cout<<m-1;
                  return 0;
              }
              
              • 0
                @ 2023-7-29 22:58:29

                AC代码:

                #include <bits/stdc++.h>
                using namespace std;
                int x;
                double i=1,n;
                int main()
                {
                    cin>>x;
                    while(n<=x)
                    {
                        n+=1/i;
                        i++;
                    }
                    cout<<i-1;//别忘了最后要减1
                    return 0;
                }
                
                • 0
                  @ 2023-7-7 21:25:58

                  #include <iostream> using namespace std; int main() { int n; cin >> n; double s = 0; int i; for (i = 1;; i++) { s += 1.0 / i; if (s > n) { break; } } cout << i; return 0; }

                  • 1

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

                  信息

                  ID
                  79
                  时间
                  1000ms
                  内存
                  16MiB
                  难度
                  2
                  标签
                  递交数
                  135
                  已通过
                  83
                  上传者