Uva 11877 Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin >> n && n > 0)
    {
        int d = 0, c = 0;
        while(n > 1)
        {
            d = n%3;
            c += n/3;
            n = d + (n/3);
            if(n == 2)
            {
                c++;
                break;
            }
        }
        cout << c << endl;
    }
    return 0;
}

Comments