HUDJ 3270 The Diophantine Equation

The Diophantine Equation

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1133    Accepted Submission(s): 292


Problem Description
We will consider a linear Diaphonic equation here and you are to find out whether the equation is solvable in non-negative integers or not.
Easy, is not it?
 

Input
There will be multiple cases. Each case will consist of a single line expressing the Diophantine equation we want to solve. The equation will be in the form ax + by = c. Here a and b are two positive integers expressing the co-efficient of two variables x and y.
There are spaces between:
1. “ax” and ‘+’
2. ‘+’ and “by”
3. “by” and ‘=’
4. ‘=’ and “c”

c is another integer that express the result of ax + by. -1000000<c<1000000. All other integers are positive and less than 100000. Note that, if a=1 then ‘ax’ will be represented as ‘x’ and same for by.
 

Output
You should output a single line containing either the word “Yes.” or “No.” for each input cases resulting either the equation is solvable in non-negative integers or not. An equation is solvable in non-negative integers if for non-negative integer value of x and y the equation is true. There should be a blank line after each test cases. Please have a look at the sample input-output for further clarification.
 

Sample Input
  
  
2x + 3y = 10 15x + 35y = 67 x + y = 0
 

Sample Output
 
 
Yes. No. Yes.




注意输入就行了:

#include<cstring>
#include<iostream>
using namespace std;

int main()
{
    char s1[20],s2[20];char q,w;
    int k;
    while(cin>>s1>>q>>s2>>w>>k)
    {
        int n,m,i,j;
        n=m=0;
        for(i=0;i<strlen(s1)-1;i++)
            n*=10,n+=s1[i]-'0';
        for(j=0;j<strlen(s2)-1;j++)
            m*=10,m+=s2[j]-'0';

        if(n==0)  n=1;
        if(m==0)  m=1;
        //printf("%d    %d\n",n,m);
        int sum,flag;
        sum=flag=0;
        for(i=0;i<=k;i+=n)
            if((k-i)%m==0)
            {
                flag=1;
                break;
            }

        if(flag) cout<<"Yes.\n\n";
        else     cout<<"No.\n\n";
    }

    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值