printЗанятие 6

printA. Amusing Numbers

Ограничения: время – 2s/4s, память – 32MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

Let us consider the set of integer numbers between 1 and N inclusive. Let us order them lexicographically (i. e. like in the vocabulary), for example, for `N` = 11 the order would be: 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9.
Let us denote the position of the number `K` in this ordering as `Q_{N,K}`. For example, `Q_{11,2}\ =\ 4`. Given numbers `K` and `M` find the smallest `N` such that `Q_{N,K}\ =\ M`.
Input
Input file contains two integer numbers `K` and `M` (`1\ ≤\ K,\ M\ ≤\ 10^9`) separated by a space.
Output
If such `N` that `Q_{N,K}\ =\ M` exists then write to the output file the smallest such `N`, otherwise write 0.

Input #1

2 4

Output #1

11

Input #2

2 1

Output #2

0

Input #3

100000001 1000000000

Output #3

100000000888888879

Input #4

1000000000 11

Output #4

0
Source: 2002-2003 ACM Northeastern European Regional Programming Contest
loading