Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ program to print any pair
- // with a given gcd G and lcm L
- #include <bits/stdc++.h>
- using namespace std;
- // Function to print the pairs
- void printPair(int g, int l)
- {
- int n = g * l;
- // iterate over all factor pairs
- for (int i = 1; i * i <= n; i++) {
- // check if a factor
- if (n % i == 0) {
- int first = i;
- int second = n / i;
- // find gcd
- int gcd = __gcd(first, second);
- // check if gcd is same as given g
- // and lcm is same as lcm l
- if (gcd == g && l % first == 0 && l % second == 0) {
- cout << first << " " << second;
- return;
- }
- }
- }
- }
- // Driver Code
- int main()
- {
- int g = 3, l = 12;
- printPair(g, l);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement