原理:辗转相除法 (数学证明:略。感兴趣的可以去证明一下)
#include <iostream>
#include <string.h>
#include <stdlib.h>
int gcd(int a, int b){
if(a<b){
int temp = a;
a = b;
b = temp;
}
int re = -1; //remainder
while(a%b != 0){
re = a%b;
a = b;
b = re;
}
return b;
}
int main(){
std::cout << gcd(21,15);
return 0;
}