Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("O3")
- #include <bits/stdc++.h>
- #include <numeric>
- using namespace std;
- #define int long long
- #define double long double
- #define endl '\n'
- #define fastio ios_base::sync_with_stdio(0); cin.tie(0)
- int gcd(int a , int b){
- if(b == 0)
- return a;
- return gcd(b , a % b);
- }
- int lcm(int a , int b){
- return a / gcd(a , b) * b;
- }
- signed main()
- {
- fastio;
- /*
- GCD(24 , 18) = 6
- LCM(24 , 18) = 72
- 24 = 2 * 2 * 2 * 3
- 18 = 2 * 3 * 3
- GCD(24 , 18) = GCD(18 , 6) = GCD(12 , 6) = GCD(6 , 6) = GCD(0 , 6)
- 10 - 3 = 7 - 3 = 4 - 3 = 1
- GCD(a , b) = GCD(b , a % b)
- GCD(24 , 18) = GCD(18 , 6) = GCD(6 , 0)
- */
- int a , b;
- cin >> a >> b;
- cout << __gcd(a , b) << " " << lcm(a , b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement