如果一个正整数N至少在两个不同的进制b1和b2下都是回文(2<=b<=10) , 则称N问双基回文数。问,对于区间 [1000000,10000000),输出第一个双基回文数。
function s(){
var done = 0;
var c = 0;
var n = 0;
for(var j = 1600000;done < 2 && j <= 10000000;j++){
for(var i = 2 ;i <= 10; i++){
c++;
n = tenToN(j,i);
if(f(n.toString())){++done; if(done == 2){return j;}}
}
done = 0;
}
console.log("not found ");
}
function f(s){
var len = s.length;
for(var i = 0;i < (len - 1) / 2 | 0;i++){
if(s[i] != s[len-i-1]){return false;}
}
return true;
}
function tenToN(num,n){
var r = num;
var ret = "";
for(;r>=n;ret=r%n + ret,r=r/n | 0);
ret = r+ret;
return ret;
}
s();