Problem Statement
You are given an int N. Find the smallest positive integer X such that the product of its digits (in decimal notation) is equal to N. Return the number of digits in X, or return -1 if such a number does not exist.
Definition
- Class:
- ProductOfDigits
- Method:
- smallestNumber
- Parameters:
- int
- Returns:
- int
- Method signature:
- int smallestNumber(int N)
- (be sure your method is public)
Constraints
- N will be between 1 and 1,000,000,000, inclusive.
Examples
1
Returns: 1
Just take X = 1. It contains 1 digit.10
Returns: 2
Here the smallest possible X is 25.26
Returns: -1
100
Returns: 3
The number 455 has 3 digits and the product of its digits is 4 * 5 * 5 = 100.2520
Returns: 4
864
Returns: 4