Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Minimum Factorization in C++
Suppose we have a positive integer x, we have to find the smallest positive integer b whose multiplication of each digit equals to x. If we have no such answer then return 0.
So, if the input is like 48, then the output will be 68
To solve this, we will follow these steps −
ret := 0, mul := 1
-
if a
return a
-
for initialize i := 9, when i >= 2, update (decrease i by 1), do −
-
while a mod i is same as 0, do −
ret := i * mul + ret
mul := mul * 10
a := a / i
-
return (if a
Example
Let us see the following implementation to get better understanding −
#includeusing namespace std; typedef long long int lli; class Solution { public: int smallestFactorization(int a) { lli ret = 0; lli mul = 1; if (a = 2; i--) { while (a % i == 0) { ret = i * mul + ret; mul *= 10; a /= i; } } return a Input
48Output
68
Advertisements
