add tests for task1

This commit is contained in:
2026-01-29 23:15:45 +05:00
parent 0658a15911
commit 1e5dbe95ec
9 changed files with 207 additions and 55 deletions

View File

@@ -0,0 +1,46 @@
#include <iostream>
#include <assert.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;
}