Tuesday, November 28, 2023

GCD

 #include <bits/stdc++.h>


using namespace std;


#define int long long int





void solve()

{   


int a, b;


cin >> a >> b;


int c = a;

int d = b;


int gcd = 0;

while(b != 0)

{

    int temp = b;

    b = a % b;

    a = temp; // a is now second big

}


gcd = a;


int lcm = (c * d)/gcd; 



cout << gcd << " " << lcm << endl;



}

                                                


main()  

{

    int tc;


    //cin >> tc;


    //while(tc--)

    {

        solve();

    }

    


    return 0;

}

No comments:

Post a Comment