UVa 993

From Algorithmist
Jump to: navigation, search

993 - Product of digits[edit]

Summary[edit]

Given a number N, determine the smallest positive integer whose digits have a product of N. (0<=N<=10^9)

Explanation[edit]

For most numbers, you need to break the number down into factors below 10, then print the digits in ascending order. The smallest number tries to have as many large factors as possible (i.e. maximum number of 9s, followed by maximum 8s, etc.), and the result is printed in ascending order.

Gotchas[edit]

  • The output must be a positive integer for all values of N.

Notes[edit]

Implementations[edit]

Optimizations[edit]

Input[edit]

3 
1 
10 
123456789

Output[edit]

1 
25 
-1

References[edit]

  1. Reference 1