int func(int n) { int result = 0; int index = 0;// 数组的下标 int byteN = 2;// 1~81得用两位数来表示 int tmp = 9; while (n > 9 * tmp)// 计算大于81的数应该用几位数字表示 82~729之间用3位数表示 { byteN++; tmp *= 9; } int[] intArr = new int[byteN]; while (byteN != 0)// 找出满足条件的i位数 { for (int j = 9; j >= 1 ; j--) { tmp = n; if (n % j == 0) { intArr[index++] = j; n /= j; break; } } if (tmp == n && n >= 10) { return -1; } --byteN; } for (int r=intArr.length-1; r>=0; r--) { result = result * 10 + intArr[r]; } return result; }
public class Test {public static int check(int n){int temp=0;
for(int i=9;i>1 && n>0;i--){
while(n%i==0){
temp=temp*10+i;
n/=i;
}
}
if(n>9)
return -1;
int sum=0;
while(temp!=0){
sum*=10;
sum+=temp%10;
temp/=10;
}
return sum;
}
public static void main(String[] args) {
System.out.println(check(36));
System.out.println(check(100));
System.out.println(check(102));
System.out.println(check(105));
} }
function func(n){ var newArr = []; (function d(n){ var star = parseInt(''.charAt.call(n,0))+1; star>9 ? newArr=[]:""; for(star;star<=9;star++){ if(n%star == 0){ newArr.push(star); n/star>9 ? (function(){n = n/star;d(n)})():newArr.push(n/star); return false; }; } })(n); return newArr.join("") || -1; } console.log(func(36)); console.log(func(37)); console.log(func(128)); console.log(func(2256)); console.log(func(729));