View Code of Problem 3866

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1e5+50;
const ll INF = 0xffffffff;

int main()
{
    ll n;
    scanf("%lld",&n);
    ll x = n;
    ll y = 0;
    int f = 1;
    while(abs(x)>=10 || f)
    {
        if(f)
        {
            f = 0;
            if(x==0)
            {
                x=(y&1)?-1:1;
            }
            else
            {
                if(x & 1)
                {
                    x = 3*x+1;
                }
                else
                    x/=2;
            }
        }
        else
        {
            x%=10;
            if(x==0)
            {
                x=(y&1)?-1:1;
            }
            else
            {
                if(x & 1)
                {
                    x = 3*x+1;
                }
                else
                    x/=2;
            }
        }
        y++;
    }
    cout<<x<<endl;
}

Double click to view unformatted code.


Back to problem 3866