Crucial Equation
Link to the question : CEQU
HINT :
We need to find whether there exists an integer solution for x and y which satisfy the equation ax + by = c. This can be done by finding the gcd of a and b and checking if it divides c.
RECOMMENDED QUESTION :
I think you will love solving a dp question after solving this one. So try your hands on this question .
SOURCE CODE :
#include<stdio.h> gcd(int m,int n){ if(n==0) return m; else return gcd(n,m%n); } int main(){ int a,b,c,t,g,e=1; scanf("%d",&t); while(t--){ scanf("%d %d %d",&a,&b,&c); g=gcd(abs(a),abs(b)); if(c%g==0) printf("Case %d: Yes\n",e); else printf("Case %d: No\n",e); e++; } return 0; }
nice and simple solution.
ReplyDelete