PivotOJ

Multiplying Digits

시간 제한: 3000ms메모리 제한: 512MB출처: BAPC 2016BOJ 13468

문제

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: f3(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 fB(X) = N?

입력

The input consists of a single line containing two integers B and N, satisfying 2 < B ≤ 10 000 and 0 < N < 263.

출력

Output the smallest positive integer solution X of the equation fB(X) = N. If no such X exists, output the word “impossible”. The input is carefully chosen such that X < 263 holds (if X exists).

예제

예제 1

입력
10 24
출력
38

예제 2

입력
10 11
출력
impossible

예제 3

입력
9 216
출력
546

예제 4

입력
10000 5810859769934419200
출력
5989840988999909996
코드를 제출하려면 로그인하세요.