4 条题解

  • 0
    @ 2019-04-05 18:00:42
    #include <cstdio>
    int main(){
        int x;
        scanf("%d",&x);
        int res=0;
        while (x!=1){
            if (x&1) x=(3*x+1)>>1,res+=2;
            else x>>=1,++res;
        }
        printf("%d\n",res);
    }
    
  • 0

    #include<iostream>
    using namespace std;

    int GetDepth(int x)
    {

    int Depth=0;
    while(x!=1)
    {
    if(x%2==0)
    x=x/2;
    else
    x=x*3+1;
    Depth++;

    }
    return Depth;
    }

    int main()
    {
    int x; cin>>x;
    int depth=GetDepth(x);
    cout<<depth<<endl;
    return 0;
    }

  • -4
    @ 2019-04-10 18:47:04
    #include<stdio.h>
    int to_one(int num);
    int count = 0;
    int main()
    {
        int num;
        scanf("%d", &num);
        to_one(num);
        printf("%d", count);
    }
    int to_one(int num)
    {
        if (num == 1)
        {
            return 0;
        }
        else if (num % 2 == 0)
        {
            num = num / 2;
            count++;
            to_one(num);
        }
        else
        {
            num = 3 * num + 1;
            count++;
            to_one(num);
        }
    
    }
    
  • -5

    #include <iostream>

    using namespace std;
    int main()
    {
    int a,b=0;
    cin>>a;
    while(a!=1)
    {
    if(a%2==0)
    a=a/2;
    else
    a=a*3+1;
    b++;
    }

    cout<<b;

    return 0;
    }

  • 1

信息

难度
2
分类
(无)
标签
递交数
2110
已通过
603
通过率
29%
被复制
5
上传者