Chapter IV recursive algorithm 1207: greatest common divisor problem

1207: greatest common divisor problem

Time limit: 1000 ms memory limit: 65536 KB
Submissions: 8655 Number through: 5471
[Title] Description
Given two positive integers, find their greatest common divisor.

Input []
input line, comprising two positive integers (<1,000,000,000).

[Output]
output a positive integer that is the greatest common divisor of two positive integers.

[Input] Sample
69
[output] Sample
3


Ideas: Recursive greatest common divisor

#include<cstdio>
#include<iostream>
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);
	
	
}
Published 108 original articles · won praise 2 · Views 2062

Guess you like

Origin blog.csdn.net/zqhf123/article/details/104424426