2 条题解

  • 0
    @ 2023-5-30 12:30:25
    #include <bits/stdc++.h>
    using namespace std;
    long long n, num;
    int main()
    {
        cin >> n;
        while (n != 1)
        {
            if (n % 2 == 0)
            {
                n /= 2;
            }
            else
            {
                n *= 3;
                n += 1;
            }
            num += 1;
        }
        cout << num;
        return 0;
    }
    
    • 0
      @ 2022-11-26 11:22:16
      #include <bits/stdc++.h>
      using namespace std;
      int num;
      int main()
      {
          int a;
          cin >> a;
          while (a != 1)
          {
              if (a % 2 == 0)
              {
                  num++;
                  a /= 2;
              }
              else if (a % 2 != 0)
              {
                  num++;
                  a *= 3;
                  a += 1;
              }
          }
          cout << num;
          return 0;
      }
      
      • @ 2023-9-13 13:02:22

        如果a%2不等于0,那么a%2!=0。 可以直接用else。

      • @ 2023-9-13 20:12:02

        @啊对

    • 1

    信息

    ID
    241
    时间
    1000ms
    内存
    16MiB
    难度
    1
    标签
    递交数
    91
    已通过
    70
    上传者