You are not logged in. Please login at www.codechef.com to post your questions!

×

Fight for Attendence - EDITORIAL

PROBLEM LINK:

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

asked 12 May '15, 00:07

guruji's gravatar image

6★guruji
113
accept rate: 0%

edited 13 May '15, 20:00

admin's gravatar image

0★admin ♦♦
19.8k350498541


@archit910 4X(4)+5X(-2)=6

link

answered 04 Mar '16, 01:42

akshayv3's gravatar image

3★akshayv3
1578
accept rate: 4%

edited 04 Mar '16, 01:42

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 .

link

answered 03 Mar '16, 23:57

archit910's gravatar image

2★archit910
820212
accept rate: 3%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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