add tests for task1
This commit is contained in:
50
3. problem_ee/solution.c
Normal file
50
3. problem_ee/solution.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ll long long
|
||||
|
||||
void ee(ll x, ll y);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ll x = 0, y = 0;
|
||||
int res;
|
||||
|
||||
|
||||
res = scanf("%lld %lld", &x, &y);
|
||||
assert(res == 2);
|
||||
|
||||
ee(x, y);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void ee(ll x, ll y) {
|
||||
ll x0 = 1, y0 = 0;
|
||||
ll x1 = 0, y1 = 1;
|
||||
|
||||
while (y != 0) {
|
||||
ll q = x / y;
|
||||
|
||||
ll t = x % y;
|
||||
x = y;
|
||||
y = t;
|
||||
|
||||
t = x1;
|
||||
x1 = x0 - q * x1;
|
||||
x0 = t;
|
||||
|
||||
t = y1;
|
||||
y1 = y0 - q * y1;
|
||||
y0 = t;
|
||||
}
|
||||
|
||||
if (x < 0) {
|
||||
x = -x;
|
||||
x0 = -x0;
|
||||
y0 = -y0;
|
||||
}
|
||||
|
||||
printf("%lld %lld %lld\n", x0, y0, x);
|
||||
}
|
||||
Reference in New Issue
Block a user