CodeForces - 681B Economy Game

题目:

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

Sample Input

Input
1359257
Output
YES
Input
17851817
Output
NO


这个题目就是暴力枚举而且,当然了,是二重循环而不是三重循环。

唯一的技巧就是,在内存循环之前,先判断了n的奇偶性,因为(56,1234)=2

加了这一句,就从30ms变成了15ms

代码:

#include
using namespace std;


int main()
{
	int n;
	while (cin>>n)
	{
		bool flag = false;
		for (int a = 0; n>=0; a++)
		{			
			if (n % 2==0)
			{
				for (int b = 0; b <= n / 123456; b++)
				{
					if ((n - 56 * b) % 1234 == 0)
					{
						flag = true;
						break;
					}
				}
			}			
			if (flag)break;
			n -= 1234567;
		}
		if (flag)cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	return 0;
}

你可能感兴趣的:(CodeForces - 681B Economy Game)