# 三个for循环变为两个

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?

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#define LL long long
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define PI 3.1415926
using namespace std;
const int N = 199999;
int main()
{
int n;
while(scanf("%d", &n)!= EOF)
{
int t = 0;
if(n % 1234567 == 0 || n % 123456 == 0 || n % 1234 == 0)
{
cout << "YES" << endl;
break;
}
for(int i = 0; i < 100; i++)
{
int q = n - 1234567 * i;
if(q > 0)     //这里一定要判断q是否大于0，否则负数也能可能除尽
{
for(int j = 0; j < 1000; j++)
{
int w = q - 123456 * j;
if(w >= 0)
{
if(w == 0 || w % 1234 == 0)
{
cout << "YES" << endl;
t = 1;
break;
}
}
}
}
if(t)
break;
}
if(t == 0)
cout << "NO" << endl;
}
return 0;
}

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 