Under construction

Still being built. Things may change

Multiplying Digits

Time limit3sMemory limit512 MB

Summary
Given base B and target N, find the smallest positive integer whose base-B digits multiply to N, or report that none exists.
Level

Hard8 of 10

Topics
Number theory, Dynamic programming, Greedy, Math
Solved
No attempts yet

Problem

Multiply together every digit of a positive integer and you get a non-negative integer. In base 10 this rule defines a function ff. For example, f(38)=3×8=24f(38) = 3 \times 8 = 24.

The same rule works in any base. Written in base 3, the number 80 is 2222, so f3(80)=2×2×2×2=16f_3(80) = 2 \times 2 \times 2 \times 2 = 16.

Solve the reverse problem. Given a base BB and a target NN, find the smallest positive integer XX with fB(X)=Nf_B(X) = N, where fB(X)f_B(X) is the product of the digits of XX written in base BB.

Input

The first line contains two integers BB and NN separated by a space (2<B≤100002 < B \le 10000, 0<N<2630 < N < 2^{63}).

Output

Print, in base 10, the smallest positive integer XX with fB(X)=Nf_B(X) = N. If no such XX exists, print impossible instead. Every input for which XX exists satisfies X<263X < 2^{63}.

Examples4

  1. Example 1

    Input
    10 24
    
    Expected output
    38
    
  2. Example 2

    Input
    10 11
    
    Expected output
    impossible
    
  3. Example 3

    Input
    9 216
    
    Expected output
    546
    
  4. Example 4

    Input
    10000 5810859769934419200
    
    Expected output
    5989840988999909996