Codeforces-Round-#357-(Div.-2)-Economy-Game

Economy Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.

Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he have bought only some houses (for1 234 567 game-coins each), cars (for 123 456 game-coins each) and computers (for 1 234 game-coins each).

Kolya is now interested, whether he could have spent all of his initial n game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers ab and c such that a × 1 234 567 + b × 123 456 + c × 1 234 = n?

Please help Kolya answer this question.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 109) — Kolya's initial game-coin score.

Output

Print "YES" (without quotes) if it's possible that Kolya spent all of his initial n coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).

Examples
input
1359257
output
YES
input
17851817
output
NO
Note

In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.

题意:就是问给定一个整数n,是否存在非负整数a,b,c,满足方程a*1234567+b*123456+c*1234=n

题目链接: Economy Game

解题思路:感觉能用拓展欧几里得,但是自己在这方面没有怎么训练,所以只能暴力了。。。。。。

代码:

// Economy Game
//题目链接:http://www.codeforces.com/contest/681/problem/B
#include
#include
using namespace std;

int fun(int a,int b,int c)
{
    return a*1234567+b*123456+c*1234;
}

int main()
{
    int n,i,flag,j,k;
    while(~scanf("%d",&n)){
        flag=0;
        for(i=n/1234567;i>=0 && !flag;i--){    //从a的最大值开始
            for(j=n/123456;j>=0 && !flag;j--){  //从b的最大值开始
                for(k=n/1234;k>=0 && !flag;k--){//从c的最大值开始
                    if(fun(i,j,k) == n) {
                        flag=1;break;
                    }
                    if((n-fun(i,j,k)) % 1234 != 0 ) break; //此时的a,b 不可能存在满足方程的c
                }
            }
        }
        if(flag) cout<<"YES";
        else    cout<<"NO";
        cout<


你可能感兴趣的:(BASE-数论,BASE-水题)