×

contest

PREREQUISITES:

Greatest common divisors.

Problem:

Given a , b , c in the equation ax+by=c; The problem is to determine if there exists at least one solution for some integers value of x and y where x, y may be negative or non-negative integers.

Explanation:

We can show this like this:

[ax + by = c] has integer solution x0,y0 implies GCD(a,b)/c. Factoring out GCD(a,b) from each side gives [\frac{1}{GCD(a,b)}(ax+by) = \frac{1}{GCD(a,b)}c]

which must still have an integer solution as GCD(a,b) obviously divides both a and b. If GCD(a,b) does not divide c there is no integer solution.

#include<bits/stdc++.h>
using namespace std;

int main(){
int t;
scanf("%d" , &t);
for(int i = 1 ; i <= t ; i++){
int a , b ;
float c;
scanf("%d %d %f" , &a , &b , &c);
// cin >> a >> b >> c;
int temp = __gcd(a , b);
if(ceil(c / temp) == floor(c/ temp))
printf("Case %d: Yes\n" , i);
else
printf("Case %d: No\n" , i);
}
}


6★guruji
113
accept rate: 0%

19.8k350498541

 1 @archit910 4X(4)+5X(-2)=6 answered 04 Mar '16, 01:42 3★akshayv3 157●8 accept rate: 4%
 0 what about a=4,b=5 and c=6?? GCd(4,5)=1 and 6 divides 1. but it has no solution . ie, no integral values of x and y satisfy the equation . answered 03 Mar '16, 23:57 820●2●12 accept rate: 3%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,851
×321

question asked: 12 May '15, 00:07

question was seen: 1,157 times

last updated: 04 Mar '16, 01:42