【codeforces 681B】【优化循环】Economy Game

传送门:http://codeforces.com/contest/681/problem/B

思路:最朴素的想法是用三重循环枚举 a,b,c ,但是其实用两重循环枚举 a,b ,再检查是否存在满足条件的c即可。


代码:

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

const int inf=0x3f3f3f3f;
const int N=3e5+10;

ll n;

int  main(){
    scanf("%lld", &n);
    ll a=1234567, b=123456, c=1234;
    for(ll i=0; ; i++){
        if(i*a>n)break;
        for(ll j=0; ; j++){
            int res=n-a*i-b*j;
            if(res<0)break;
            if(res%c == 0){
                puts("YES");
                exit(0);
            }
        }
    }
    puts("NO");
    return 0;
}
B. 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 (for 1 234 567 game-coins each), cars (for 123 456 game-coins each) and computers (for 1 234game-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 thata × 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.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值