Connection Status:
Competition Arena > ProductOfDigits
SRM 424 · 2008-11-05 · by Gluk · Simple Math
Class Name: ProductOfDigits
Return Type: int
Method Name: smallestNumber
Arg Types: (int)
Problem Statement

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.

Constraints

  • N will be between 1 and 1,000,000,000, inclusive.
Examples
0)
1
Returns: 1

Just take X = 1. It contains 1 digit.

1)
10
Returns: 2

Here the smallest possible X is 25.

2)
26
Returns: -1
3)
100
Returns: 3

The number 455 has 3 digits and the product of its digits is 4 * 5 * 5 = 100.

4)
1024
Returns: 4

Submissions are judged against all 160 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ProductOfDigits with a public method int smallestNumber(int N) · 160 test cases · 2 s / 256 MB per case

Submitting as anonymous