# 4 条题解

• @ 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);
}

• @ 2019-01-15 10:08:39

#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;
}

• @ 2021-01-17 17:53:35

老师，Depth是什么意思

• @ 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);
}

}

• @ 2021-01-25 15:59:59

#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

(无)

1150

257

22%

3