Răspuns :
#include <iostream>
using namespace std;
int main ()
{
long long int n;
int cnt = 1;
cin >> n;
while(n != 1)
{
cnt ++;
if(n % 2 == 0)
n /= 2;
else
n = 3 * n + 1;
//cout << n << " ";
}
cout << cnt;
return 0;
}
Asta e solutia oficiala.
using namespace std;
int main ()
{
long long int n;
int cnt = 1;
cin >> n;
while(n != 1)
{
cnt ++;
if(n % 2 == 0)
n /= 2;
else
n = 3 * n + 1;
//cout << n << " ";
}
cout << cnt;
return 0;
}
Asta e solutia oficiala.
#include <iostream>
using namespace std;
long long nr,n,t;
int main()
{
cin>>n;
t=n;
while(t!=1)
{
if(t%2==0) t=t/2;
else t=t*3+1;
nr++;
}
cout<<nr+1;
return 0;
}
using namespace std;
long long nr,n,t;
int main()
{
cin>>n;
t=n;
while(t!=1)
{
if(t%2==0) t=t/2;
else t=t*3+1;
nr++;
}
cout<<nr+1;
return 0;
}