Untitled
raw download clone
TEXT
views 19
,
size 584 b
COLLATZ

#include <iostream>
using namespace std;

int main()
{
    int n , cnt=1;

    cin >> n;

    while(n!=1)
    {
        if(n%2==0)
            n=n/2;
        else
            n=3*n+1;
        cnt++;
        //cout << n << " ";
    }

    cout << cnt;


    return 0;
}

SUMPRODMAX3

#include <iostream>
using namespace std;

int main()
{
    int n , a , b , c;
    cin >> n;

    a=b=c=n/3;
    if(n%3==1)
        c=c+1;
    else
        if(n%3==2)
            c=c+1,b=b+1;
    cout << a << " " << b << " " << c;

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.