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

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 .

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

1 Like