Geeksforgeeks

Error

×

Given a positive integer **N**, find the smallest number **S **such that the product of all the digits of **S **is equal to the number **N**. If there's no such number, Print "-1".

**Example 1:**

Input:N =100Output:455Explanation:4*5*5 = 100. There are no numbers less than 455 with the product of it's digit as 100.

**Example 2:**

Input:N =26Output:-1Explanation:There are no numbers which can form a product of 26 with its digits.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **getSmallest()** which takes an Integer N as input and returns the answer as a String.

**Expected Time Complexity:** O(log(N))

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 <= N <= 10^{9}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Digit multiplier

...