#P4226. Counterexample for Greedy Digit Product Factorization

    ID: 17473 Type: Default 1000ms 256MiB

Counterexample for Greedy Digit Product Factorization

Counterexample for Greedy Digit Product Factorization

For a given positive integer (n), define its digit product in base (b) as (F(n,b)), which is the product of the digits of (n) when written in base (b). For example, (F(3338,10)=216).

Consider the following problem: given a base (b), there is an algorithm that, for a given (p), finds the smallest (n) such that (F(n,b)=p) by greedily trying divisors from (b-1) down to (2) until (p) becomes (1). For some bases this greedy algorithm yields the correct (minimal) answer (for example, when (b=10) and (p=216), the result is (389) which is minimal), but for other bases it does not. For instance, when (b=9) and (p=216), the greedy method produces the answer (3338) (in base 9) whereas the true minimal (n) is (666) (in base 9).

Your task is: given a base (b), produce a counterexample instance by providing a value (p) and its corresponding minimal (n) such that the greedy algorithm fails, i.e. the greedy solution is different from the minimal (n). However, due to computational limitations, the value (p) (i.e. the product of digits) must not exceed (10^{18}). If the smallest counterexample has (p > 10^{18}) or if such a counterexample does not exist for the given (b), output (-1).

inputFormat

The input consists of a single integer representing the base (b) (with (b \ge 2)).

outputFormat

If a valid counterexample exists with (p \leq 10^{18}), output two space‐separated integers: the first is (p) and the second is the minimal (n) satisfying (F(n,b)=p). Otherwise, output (-1).

sample

9
216 666