第四章再帰アルゴリズム1207:最大公約数を求める問題


1207:最大公約数の問題を求めます
時間制限:1000 msメモリ制限:65536 KBコミット数:8655パス数:5471【題名説明】2つの正の整数を与え、それらの最大公約数を求める.
【入力】2つの正の整数(<10000000)を含む1行を入力します.
【出力】正の整数、すなわち2つの正の整数の最大公約数を出力する.
【入力サンプル】6 9【出力サンプル】3
構想:再帰的に最大公約数を求める
#include
#include
using namespace std;
int gcd(int ,int );
int main(){
     
	int m,n;
	cin>>m>>n;
	cout<<gcd(m,n)<<endl;
	return 0;
}
int gcd(int m,int n)
{
     
	if(m%n==0) return n;
	else return gcd(n,m%n);
	
	
}