TopcoderArchiveVisit Topcoder
SRM5 Nov 2008
SRM 424

ProductOfDigits

Problem statement, definition, constraints, and public examples.

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. 1
    Returns: 1
    Just take X = 1. It contains 1 digit.
  2. 10
    Returns: 2
    Here the smallest possible X is 25.
  3. 26
    Returns: -1
  4. 100
    Returns: 3
    The number 455 has 3 digits and the product of its digits is 4 * 5 * 5 = 100.
  5. 2520
    Returns: 4
  6. 864
    Returns: 4
Back to all problems