您的位置:首页 > 其它

CodeForces 681B

2016-07-10 11:19 495 查看
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121183#problem/G

G - Economy Game
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
681B

Description

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).

Sample Input

Input
1359257


Output
YES


Input
17851817


Output
NO


题意:给出一个游戏币数求买买房车电脑能不能恰好花完

不思考的暴力 超时

一个技巧减少一层循环
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int main(){
ll n;
while(cin>>n){

int a=n/1234567;
int b=n/123456;
int c=n/1234;

int flag=0;
for(int i=0;i<=a+1;++i){
for(int j=0;j<=b+1;++j){
if(((ll)n-(ll)i*1234567-(ll)j*123456)>=0&&((ll)n-(ll)i*1234567-(ll)j*123456)%1234==0){flag=1;goto aaa;}//@1

}
}
aaa:;
if(!flag)cout<<"NO\n";
else cout<<"YES\n";
}
return 0;
}
@1 如果此处再把c循环一遍一定超时
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: