110,536
社区成员
发帖
与我相关
我的任务
分享
public long getQ(long N) {
ArrayList<Integer> list = new ArrayList<Integer>();
long Q = 0;
if (N > 1) {
factorization(N, list);
Collections.sort(list);
for (int index = 0; index < list.size(); index++) {
Q = Q * 10 + list.get(index).intValue();
}
} else {
Q = -1;
}
return Q;
}
private void factorization(long N, ArrayList<Integer> list) {
int factor;
for (factor = 9; factor > 1; factor--) {
if (N % factor == 0) {
list.add(new Integer(factor));
factorization(N / factor, list);
break;
}
}
if (N > 1 && factor <= 1) {
list.clear();
list.add(new Integer(-1));
}
}
public static long getMinNumber(long N) {
long Q = 0;
long temp = N;
double x = 0;
int index = 9;
while (true) {
for (index = 9; index >1; index--) {
if (temp % index == 0)
break;
}
if (index <= 1) {
return -1;
} else {
Q = (long) (Q + index * Math.pow(10, x));
temp = temp / index;
x++;
if (temp <= 1)
return Q;
}
}
}