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:
48Output:
68
Example 2
Input:
15Output:
35
Solution:
class Solution { public: int smallestFactorization(int a) { if(a<10)return a; vector<int> tmp; for(int i=9;i>1;i--) while(a%i==0) { a = a/ i; tmp.push_back(i); } if(a>10) return 0; long long ret =0; for(int i =tmp.size()-1;i>=0;i--) { ret = ret*10+tmp[i]; if(ret>2147483647) return 0; } return ret; } };