add task 2
This commit is contained in:
BIN
2. problem_cf/ex.png
Normal file
BIN
2. problem_cf/ex.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 MiB |
54
2. problem_cf/solution.c
Normal file
54
2. problem_cf/solution.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
Problem CF -- непрерывные дроби
|
||||||
|
|
||||||
|
Вам на вход приходят числитель и знаменатель дроби.
|
||||||
|
|
||||||
|
Ваша задача: написать программу выдающую на стандартный вывод представление цепной дробью.
|
||||||
|
|
||||||
|
Пример 1
|
||||||
|
|
||||||
|
Ввод: 1 3
|
||||||
|
Вывод: 0 3
|
||||||
|
|
||||||
|
Пример 2
|
||||||
|
|
||||||
|
Ввод: 43 19
|
||||||
|
Вывод: 2 3 1 4
|
||||||
|
|
||||||
|
Пример 3
|
||||||
|
|
||||||
|
Ввод: 345 678
|
||||||
|
Вывод: 0 1 1 27 1 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#define ull unsigned long long
|
||||||
|
|
||||||
|
void cf(ull x, ull y);
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
ull x = 0, y = 0;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = scanf("%llu %llu", &x, &y);
|
||||||
|
assert(res == 2);
|
||||||
|
|
||||||
|
cf(x, y);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cf(ull x, ull y) {
|
||||||
|
ull a = (x > y) ? x : y;
|
||||||
|
ull b = (x < y) ? x : y;
|
||||||
|
|
||||||
|
ull q = a / b;
|
||||||
|
ull r = a % b;
|
||||||
|
|
||||||
|
while (r > 0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user