#include<iostream> using namespace std; int gcd(int a,int b) { return a%b?gcd(b,a%b):b; } int main() { int m,n; while(cin>>m>>n) { int sum=m+n; int Sum=m*n; m=m>n?m:n; n=sum-m; int k=gcd(m,n); cout<<k<<" "<<Sum/k<<endl; } }
2024-04-12 18:01:32
#include<iostream> using namespace std; int gcd(int a,int b) { return a%b?gcd(b,a%b):b; } int main() { int m,n; while(cin>>m>>n) { int sum=m+n; int Sum=m*n; m=m>n?m:n; n=sum-m; int k=gcd(m,n); cout<<k<<" "<<Sum/k<<endl; } }