Multiplying Digits
Time limit3sMemory limit512 MB
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 . For example, .
The same rule works in any base. Written in base 3, the number 80 is 2222, so .
Solve the reverse problem. Given a base and a target , find the smallest positive integer with , where is the product of the digits of written in base .
Input
The first line contains two integers and separated by a space (, ).
Output
Print, in base 10, the smallest positive integer with . If no such exists, print impossible instead. Every input for which exists satisfies .