Ограничения: время – 500ms/1000ms, память – 32MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод
Послать решение Blockly Посылки Темы Где Обсудить (0)
Let's take any natural number `K` and generate an infinite sequence `S` according to the following rules.
- `S_i` is `i`, where `1\ ≤\ i\ ≤\ K`.
- `S_i` is the least natural number so, that `gcd(S_i,\ S_{i-1})\ ≥\ K` and `S_i\ ≠\ S_j`, where `1\ ≤\ j\ <\ i` and `i\ >\ K` and gcd mean "greatest common divisor".
For example, for `K=3` first twenty terms are 1, 2, 3, 6, 9, 12, 4, 8, 16, 20, 5, 10, 15, 18, 21, 7, 14, 28, 24, 27.
Sooner or later in this sequence there will be all natural numbers. Write the program, which calculates the least
natural number that is missing among first `N` terms, the greatest number among first `N` terms, and `N`-th term.
Input
The first line of the input file contains two integers `K` and `N` (`1\ ≤\ K\ ≤\ 100`, `1\ ≤\ N\ ≤\ 10000`), separated by one space. First `N` terms of the sequence `S` do not exceed 30000 for given `K`.
Output
Write into the output file the one line containing three integers, separated by spaces. They are the least natural number that is missing among first `N` terms of the sequence `S`, the greatest number among first `N` terms of the sequence, and `N`-th term.