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;
}

HUDJ 3270 The Diophantine Equation

时间: 2024-08-01 21:41:17

HUDJ 3270 The Diophantine Equation的相关文章

杭电 3270 The Diophantine Equation

http://acm.hdu.edu.cn/showproblem.php?pid=3270 The Diophantine Equation Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1146    Accepted Submission(s): 297 Problem Description We will consider a

欧拉工程第66题:Diophantine equation

题目链接 脑补知识:佩尔方差 上面说的貌似很明白,最小的i,对应最小的解 然而我理解成,一个循环的解了,然后就是搞不对,后来,仔细看+手工推导发现了问题.i从0开始变量,知道第一个满足等式的解就是最小解. 问题转化为求根号n的连分数问题,分子就是x,分母就是y 要求的分子,分母,问题又转化为:根号n的连分数表示,对,求出其连分数表示就OK了 先求出a的序列是什么? 第64题,就是求a的序列的. a求出来了,要求出分子分母的表达式. 第65题,就是已经知道了a的序列,求分子,当然也可以求分母的 分

hdoj-1299-Diophantus of Alexandria【判断素因子个数+组合数】

Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2853 Accepted Submission(s): 1099 Problem Description Diophantus of Alexandria was an egypt mathematician living in Alexand

Codeforces 520E. Pluses everywhere 数学

520E - Pluses everywhere/521C - Pluses everywhere Idea: Endagorion Preparation: gchebanov, DPR-pavlin Consider some way of placing all the pluses, and a single digit di (digits in the string are numbered starting from 0 from left to right). This digi

hdu 1299 Diophantus of Alexandria (数论)

Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2269    Accepted Submission(s): 851 Problem Description Diophantus of Alexandria was an egypt mathematician living in Ale

Codeforces Codeforces Round #484 (Div. 2) E. Billiard

Codeforces Codeforces Round #484 (Div. 2) E. Billiard 题目连接: http://codeforces.com/contest/982/problem/E Description Consider a billiard table of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at t

Codeforces 1063D Candies for Children

题目大意 给定整数 $n, k, l, r$,$1\le n, k \le 10^{11}$,$1\le l, r \le n$ . 令 $ m = r - l + 1$,若 $m \le 0$,$m\gets m + n$ . 未知数 $x\in \mathbb{Z}$ 满足 $ 0 \le x \le n$,且满足 $ k \bmod (n + x) = 0$ 且 $m = n$ :或者 $ k \bmod (n + x) \ne 0$ 且 $0 \le k \bmod (n + x) -

从“n!末尾有多少个0”谈起

在学习循环控制结构的时候,我们经常会看到这样一道例题或习题.问n!末尾有多少个0?POJ 1401就是这样的一道题. [例1]Factorial (POJ 1401). Description The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the

Project Euler 108:Diophantine reciprocals I 丢番图倒数I

Diophantine reciprocals I In the following equation x, y, and n are positive integers. For n = 4 there are exactly three distinct solutions: What is the least value of n for which the number of distinct solutions exceeds one-thousand? NOTE: This prob