山科校赛——有解吗?(数学提公因式)

问题 D: 有解吗?

时间限制: 1 Sec   内存限制: 128 MB
提交: 410   解决: 134
[ 提交][ 状态][ 讨论版]

题目描述

给出方程 a * 1234567 + b * 123456 + c * 1234 = n。其中 a、b、c 均为非负整数变量,n(1 <= n <= 
10 ^ 9)为给出整数常量。判断方程是否有解。 

输入

一个整数 n 

输出

如果有解,输出“YES”;无解,输出“NO”。 

样例输入

1234567

样例输出

YES
a * 1234567 + b * 123456 + c * 1234 = n => 1234*(a*1000+b*100+c)+a*567+b*56=n

根据a,b的范围二重循环,判断C是否>=0&&<=100000(C估计的最大值,不写也行)

#include <iostream>

#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <stack>
using namespace std;
typedef long long ll;
#define PI 3.1415926535897932
#define E 2.718281828459045
#define INF 0xffffffff//0x3f3f3f3f
#define mod 1000000007
const int MOD=1e9+7;

const int M=1005;
int n,m;

int main()
{
    int i,j,k,t;
    while(~scanf("%d",&n))
    {
        if(n%1234==0||n%123456==0||n%1234567==0)
        {
            printf("YES\n");
            continue;
        }
        bool op=0,flag=true;
        for(i=0; i<1000; i++)
        {
            //flag=true;
            for(j=0; j<10000; j++)
            {
                int tmp=n-567*i-j*56;
                if(tmp%1234==0)
                {
                    tmp/=1234;
                    int u=tmp-i*1000-j*100;
                    if(u>=0&&u<100000)
                    {
                        op=1;
                        flag=false;
                        break;
                    }
                    else continue;
                }
                else
                {
                    continue;
                }
            }
            if(!flag)break;
        }
        if(op)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值