Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int gcd(int a, int b)
- {
- while(b!=0)
- {
- int tem;
- tem=b;
- b=a%b;
- a=tem;
- }
- return a;
- }
- int main()
- {
- int a, b;
- int tc;
- cin>>tc;
- while(tc--)
- {
- cin>>a>>b;
- int gd, lcm;
- gd=gcd(a, b);
- lcm=(a*b)/gd;
- if(gd%a==0&&lcm%b==0) cout<<gd<<" "<<lcm<<endl;
- else cout<<-1<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement