题目描述
求两个自然数M和N的最大公约数(M,N都在长整型范围内)
样例输入
45 60
样例输出
15
AC
#include<iostream>
using namespace std;
int gcd(int a,int b){
if(a%b==0){
return b;
}
else{
return gcd(b,a%b);
}
}
main(){
int a,b;
cin>>a>>b;
cout<<gcd(a,b);
}
题目描述
求两个自然数M和N的最大公约数(M,N都在长整型范围内)
样例输入
45 60
样例输出
15
AC
#include<iostream>
using namespace std;
int gcd(int a,int b){
if(a%b==0){
return b;
}
else{
return gcd(b,a%b);
}
}
main(){
int a,b;
cin>>a>>b;
cout<<gcd(a,b);
}