问题:多组样例输入,输入两个数,输出其最大公约数以及最小公倍数
最大公约数代码:
#include <iostream>
using namespace std;
int GCD(int a,int b){
if(b==0){
return a;
}
else{
return GCD(b,a%b);
}
}
int main()
{
int a,b;
while(cin>>a>>b)
{
cout<<GCD(a,b)<<endl;
} return 0;
}
求最小公倍数代码:
#include<iostream>
#include<cstdio>
using namespace std;
int GCD(int a,int b){
if(b==0){
return a;
}
else{
return GCD(b,a%b);
}
}
int LCM(int a,int b){
return a*b/GCD(a,b);
}
int main(){
int a,b;
while(cin>>a>>b){
cout<<LCM(a,b)<<endl;
}
return 0;
}