CF #357 div2 B Economy Game

B. Economy Game
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 (for 1 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 a, b 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


题目大意就是求是否存在非负整数a,b,c
使得a*1234567+b*123456+c*1234=n

一开始想用遍历觉得n^3太大了就没往下想,
然后用的相减
即这个数循环减去1234567至小于1234567后减去123456,
依次类推

现在想来有明显的逻辑问题
//这个数可以减去一个1234657后虽然仍大于1234567但可以整除1234

看了别人代码发现只要两层循环后取模1234就可以
感觉自己是个智障。。。。。

#include
int main()
{
    int n,a,b,flag=0;
    scanf("%d",&n);
    for(a=0;a*1234567<=n;a++)
    {
        for(b=0;a*1234567+b*123456<=n;b++)
        {
            if((n-a*1234567-b*123456)%1234==0)
            {
                flag=1;
                break;
            }
        }
    }
    if(flag==1)
    puts("YES");
    else
    puts("NO");
    return 0;
}

你可能感兴趣的:(Codeforces,水题)