#include <stdio.h>
int gcd_diff(int a, int b) {
while(a!=b) {
if(a > b) {
a = a - b;
} else{
b = b - a;
}
}
return a;
}
int gcd_euclid(int a, int b) {
int r;
while(b) {
r = a % b;
a = b;
b = r;
}
return a;
}
int euclid_rec(int a, int b) {
if(b == 0) {
return a;
} else {
return euclid_rec(b, a % b);
}
}
int gcd_rec(int a, int b) {
if(a == b) {
return a;
} else {
if(a > b) return gcd_rec(a - b, b);
else
return gcd_rec(a, b -a);
}
}
int main() {
int vec[] = {22,4,8,10,1012,72},
n = sizeof(vec)/sizeof(vec[0]),
gcd;
gcd = euclid_rec(vec[0],vec[1]);
for(int i = 2; i <= n; ++i) {
gcd = euclid_rec(gcd, vec[i]);
}
return(0);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgZ2NkX2RpZmYoaW50IGEsIGludCBiKSB7CiAgICB3aGlsZShhIT1iKSB7CiAgICAgIGlmKGEgPiBiKSB7CiAgICAgICAgYSA9IGEgLSBiOwogICAgICB9IGVsc2V7CiAgICAgICAgYiA9IGIgLSBhOyAKICAgICAgfQogICAgfQogICAgcmV0dXJuIGE7Cn0KCmludCBnY2RfZXVjbGlkKGludCBhLCBpbnQgYikgewogICAgaW50IHI7CiAgICB3aGlsZShiKSB7CiAgICAgIHIgPSBhICUgYjsKICAgICAgYSA9IGI7CiAgICAgIGIgPSByOwogICAgfSAgCiAgICByZXR1cm4gYTsKfQoKaW50IGV1Y2xpZF9yZWMoaW50IGEsIGludCBiKSB7CiAgICBpZihiID09IDApIHsKICAgICAgcmV0dXJuIGE7CiAgICB9IGVsc2UgewogICAgICByZXR1cm4gZXVjbGlkX3JlYyhiLCBhICUgYik7CiAgICB9Cn0KCmludCBnY2RfcmVjKGludCBhLCBpbnQgYikgewogICAgaWYoYSA9PSBiKSB7CiAgICAgIHJldHVybiBhOwogICAgfSBlbHNlIHsKICAgICAgaWYoYSA+IGIpIHJldHVybiBnY2RfcmVjKGEgLSBiLCBiKTsKICAgICAgZWxzZQogICAgICAgICAgICAgICAgcmV0dXJuIGdjZF9yZWMoYSwgYiAtYSk7IAogICAgfQp9CgppbnQgbWFpbigpIHsKICAgIGludCB2ZWNbXSA9IHsyMiw0LDgsMTAsMTAxMiw3Mn0sCiAgICBuID0gc2l6ZW9mKHZlYykvc2l6ZW9mKHZlY1swXSksIAogICAgZ2NkOwoKICAgIGdjZCA9IGV1Y2xpZF9yZWModmVjWzBdLHZlY1sxXSk7CgogICAgZm9yKGludCBpID0gMjsgaSA8PSBuOyArK2kpIHsKICAgICAgZ2NkID0gZXVjbGlkX3JlYyhnY2QsIHZlY1tpXSk7CiAgICB9CgogICAgcHJpbnRmKCIlZCIsIGdjZCk7CgogICAgcmV0dXJuKDApOwp9