# 625. Minimum Factorization

Given a positive integer `a`, find the smallest positive integer `b` whose multiplication of each digit equals to `a`.

If there is no answer or the answer is not fit in 32-bit signed integer, then return 0.

Example 1
Input:

``````48
``````

Output:

``````68
``````

Example 2
Input:

``````15
``````

Output:

``````35
``````

``````class Solution {
public:
int smallestFactorization(int a) {
if (a == 1) return 1;
string res = "";
for (int k = 9; k >= 2; --k) {
while (a % k == 0) {
res = to_string(k) + res;
a /= k;
}
}
if (a > 1) return 0;
long long num = stoll(res);
return num > INT_MAX ? 0 : num;
}
};
``````

``````class Solution {
public:
int smallestFactorization(int a) {
if (a < 10) return a;
long long res = 0, cnt = 1;
for (int i = 9; i >= 2; --i) {
while (a % i == 0) {
res += cnt * i;
if (res > INT_MAX) return 0;
a /= i;
cnt *= 10;
}
}
return (a == 1) ? res : 0;
}
};
``````

https://discuss.leetcode.com/topic/92920/concise-c-solution-10-lines-3ms

https://discuss.leetcode.com/topic/92998/c-clean-code-7-line-3-solutions/2

LeetCode All in One 题目讲解汇总(持续更新中…)

 微信打赏 Venmo 打赏
（欢迎加入博主的知识星球，博主将及时答疑解惑，并分享刷题经验与总结，试运营期间前五十位可享受半价优惠～）

×

Help us with donation