Wednesday 15 July 2015

ANARC09B


Tiles of Tetris, Not!

Link to the question : ANARC09B 

HINT :

A very simple question. By looking at the example or by just getting the feel of the question you will understand that all you need to find is the least common multiple of the two numbers.

RECOMMENDED QUESTION :

Try this p&c question after this one.

SOLUTION :

 #include<iostream>

 using namespace std;

int main()

{



    long long  a=1,b=1,g;



    while(a!=0 && b!=0)

    {

        cin>>a>>b;

        if(a!=0 && b!=0) {

        long long i;

        while(a%2==0 && b%2==0)

        {

            a=a/2;

            b=b/2;

        }

        long long

         s;

        if(a<b)

            s=a;

        else s=b;

        for(i=3;i<=s;i=i+2)

        {

            while(a%i==0 && b%i==0)

            {

                a=a/i;

                b=b/i;

            }

        }

        cout<<a*b<<endl;

    } }

    return 0;



}



No comments:

Post a Comment