P17767 [Kattis] Multiplyingdigits
提高
题目描述

For every positive integer we may obtain a non-negative integer by multiplying its digits. This defines a function $f$, e.g. $f(38) = 24$.

This function gets more interesting if we allow for other bases. In base $3$, the number $80$ is written as $2222$, so: $f_3(80) = 16$.

We want you to solve the reverse problem: given a base $B$ and a number $N$, what is the smallest positive integer $X$ such that $f_ B(X) = N$?

-----Input-----
The input consists of a single line containing two integers $B$ and $N$, satisfying $2 < B \leq 10000$ and $0 < N < 2^{63}$.

-----Output-----
Output the smallest positive integer solution $X$ of the equation $f_ B(X) = N$. If no such $X$ exists, output the word “impossible”. The input is carefully chosen such that $X < 2^{63}$ holds (if $X$ exists).

-----Examples-----
Sample Input 1:
10 24
Sample Output 1:
38

Sample Input 2:
10 11
Sample Output 2:
impossible

Sample Input 3:
9 216
Sample Output 3:
546

输入格式

见题面

输出格式

见题面

样例输入
10 24
样例输出
38