solve-play with math # ENIGMATH on spoj
ENIGMATH - PLAY WITH MATH
You would have been fed up with competitive programming questions so far, now it is time to solve little math.
Assume you have a equation A * x - B * y = 0
For a given value of A and B, find the minimum positive integer value of x and y that satisfies this equation.
Input
First line contains T, number of test cases 0 <= T <=1000 followed by T lines.
First line of each test case contains two space seperated integers A and B. 1 <= A, B <=1 000 000 000.
Output
For each test case, output a single line containing two integers x and y (seperated by a single space)
.
SOLUTION-
#include<stdio.h>
int main()
{ long long int t,a,b,c,d,m,n,l,x;
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld",&a,&b);
m=a;
n=b;
while(b!=0)
{
x=a%b;
a=b;
b=x;
}
l=(m*n)/a;
c=l/m;
d=l/n;
printf("%lld %lld",c,d);
printf("\n");
}
}
Comments
Post a Comment