Codeforces Economy Game

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

typedef long long LL;
typedef unsigned long long ull;

void fun()
{
    for(int i=0; ; i++)
    {
        if((i * 123456) > 1000000000)
        {
            cout << i;
            break;
        }
    }
}

int main()
{
    LL n;
    //fun();
    while(cin >> n)
    {
        int i,j;
        LL ans=0;
        bool possible=false;

        for(i=0; i<=811; i++)
        {
            for(j=0; j<=8101; j++)
            {
                ans = (n - i * 1234567 - j * 123456); //cout << ans << " ";

                if(!(ans % 1234) and ans >=0) // ans >=0 to avoid negative value. ans er value 10^9 corss korle eta emnitei impossible. ar long long data type e seta negative value dekhabe.. tai ans >= 0 check kora :)
                {
                    possible=true;
                    break;
                }
            }

            if(possible)
            {
                break;
            }
        }

        if(possible)
        {
            cout << "YES\n";
        }

        else
        {
            cout << "NO\n";
        }
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number