49 lines
710 B
C
49 lines
710 B
C
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define ull unsigned long long
|
|
#define ll long long
|
|
|
|
ull gcd_cycle(ll x, ll y);
|
|
ull gcd_recursive(ull x, ull y);
|
|
|
|
int main() {
|
|
ull x = 0, y = 0, g;
|
|
int res;
|
|
|
|
res = scanf("%llu %llu", &x, &y);
|
|
assert(res == 2);
|
|
g = gcd_cycle(x, y);
|
|
printf("%llu\n", g);
|
|
return 0;
|
|
}
|
|
|
|
ull gcd_recursive(ull x, ull y) {
|
|
ull q;
|
|
if (y > x)
|
|
return gcd_recursive(y, x);
|
|
assert (y > 0);
|
|
q = x % y;
|
|
if (q == 0)
|
|
return y;
|
|
return gcd_recursive(y, q);
|
|
}
|
|
|
|
ull gcd_cycle(ll x, ll y) {
|
|
x = llabs(x);
|
|
y = llabs(y);
|
|
|
|
if (x == 0) return y;
|
|
if (y == 0) return x;
|
|
|
|
while (y != 0) {
|
|
ll r = x % y;
|
|
x = y;
|
|
y = r;
|
|
}
|
|
|
|
return x;
|
|
}
|
|
|