Thursday, 23 July 2015

ENIGMATH

Standard

PLAY WITH MATH

Link to the question : ENIGMATH 

HINT :

A question similar to CEQU. 
In order for x and y to satisfy the equation a*x = b*y , a*x should be equal to the lcm of (a,b). Similarly, b*y should also be equal to the lcm of the coefficients.

RECOMMENDED QUESTION :

A similar question to this : CEQU.
You will surely enjoy solving it.

SOURCE CODE :

 #include <stdio.h>
#include<math.h>

int main()
{
    int t;
    long long int a,s,b,i;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld%lld",&a,&b);
        while(a%2==0 && b%2==0)
        {
            a=a/2;
            b=b/2;
        }
        if(a>b)
            s=b;
        else
            s=a;
        for(i=3;i<=sqrt(s);i=i+2)
        {
            while(a%i==0 && b%i==0)
            {
                a=a/i;
                b=b/i;
            }
        }
        printf("%lld %lld\n",b,a);
    }
    return 0;
}

0 comments:

Post a Comment