gcd-模板+最小公倍数
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 int GCD(int a,int b) 6 { 7 for(;a>0&&b>0;a>b?a%=b:b%=a); 8 return a+b;//最大公约数; 9 } 10 int main() 11 { 12 int a,b; 13 while(cin>>a>>b) 14 { 15 int ans=GCD(a,b); 16 cout<<ans<<endl; 17 cout<<a*b/ans<<endl;//最小公倍数; 18 } 19 return 0; 20 }
1 ll gcd (ll a, ll b) 2 { 3 return ( a ? gcd(b%a, a) : b ); 4 }