最大公约数gcd,最小公倍数lcm
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 5 int x,y; 6 7 int gcd(int a,int b){ 8 if(b==0) return a; 9 return gcd(b,a%b); 10 } 11 12 int lcm(int a,int b){ 13 return a*b/gcd(a,b); 14 } 15 16 int main(){ 17 cin>>x>>y; 18 cout<<gcd(x,y)<<endl; 19 cout<<lcm(x,y)<<endl; 20 return 0; 21 }