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

37
3. problem_ee/README.md Normal file
View File

@@ -0,0 +1,37 @@
# Problem EE - расширенный алгоритм E
Даны два целых числа `x` и `y`
Необходимо найти их наибольший общий делитель `d` и целые, возможно отрицательные числа `a` и `b`, такие, что:
```
ax + by = d
```
Используйте тип `long long` для всех чисел
Посылка должна состоять из программы, считывающей со стандартного ввода два числа `x` и `y` и выводящей на стандартный вывод три числа: `a`, `b`, `d`.
## Пример 1
| Ввод | Вывод |
| ------------- | -------------- |
| `2 1` | `0 1 1` |
## Пример 2
| Ввод | Вывод |
| ------------- | -------------- |
| `3 2` | `1 -1 1` |
## Пример 3
| Ввод | Вывод |
| ------------- | -------------- |
| `2 4` | `1 0 2` |
# Решение
```c
```

50
3. problem_ee/solution.c Normal file
View 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);
}