public class Solution {
public int smallestFactorization(int n) {
if ( n < 10) return n;
List<Integer> temp = new ArrayList<Integer>();
for (int i = 9; i > 1; i--) {
while (n % i == 0) {
n /= i;
temp.add(i);
}
}
if (n != 1) return 0; // n is a prime
long res = 0;
for (int i = temp.size() - 1; i >=0; i--) {
res = res * 10 + temp.get(i);
if (res >= Integer.MAX_VALUE) return 0;
}
return (int)res;
}
}
public class Solution {
public int smallestFactorization(int a) {
if (a <= 1) {
return a;
}
long num = 0;
int factor = 9;
long orderOfMagnitude = 1;
while (a != 1 && factor > 1) {
while (a % factor == 0) {
a /= factor;
num += factor * orderOfMagnitude;
orderOfMagnitude *= 10L;
}
factor--;
}
if (a != 1 || num > Integer.MAX_VALUE) {
return 0;
}
return (int) num;
}
}