决定为factorization,prime这类题专门开个section
Minimum Factorization
题目要求每位乘积是数a,实际上就是找a的“质数因子”。而这里要求只要这个“质数因子”能填在某位上就可以,不一定是“质数”,本质上就是找符合条件的“单个”数。所以从9~1挨个加。
public class Solution {
public int smallestFactorization(int a) {
if (a < 2)
return a;
long res = 0, mul = 1;
for (int i = 9; i >= 2; i--) {
while (a % i == 0) {
a /= i;
System.out.println(mul + " " + i + " " + res);
res = mul * i + res;
mul *= 10;
}
}
return a < 2 && res <= Integer.MAX_VALUE ? (int)res : 0;
}
}