6300846559 is such that 6 is divisible by 2; 63, by 3; 630, by 5; 6300, by 7; and, in general, if you take its first N digits, it will be divisible by the N-th prime.
There is only one other such 10 digit number: can you find it?
The following gawk script runs in 0.04 seconds in my Linux machine, and produces 0000000000, 6300846559, and
8757193191BEGIN {
for (a=0; a<10; a++) if (check(a,2)) {
for (b=0; b<10; b++) if (check(a b,3)) {
for (c=0; c<10; c++) if (check(a b c,5)) {
for (d=0; d<10; d++) if (check(a b c d,7)) {
for (e=0; e<10; e++) if (check(a b c d e,11)) {
for (f=0; f<10; f++) if (check(a b c d e f,13)) {
for (g=0; g<10; g++) if (check(a b c d e f g,17)) {
for (h=0; h<10; h++) if (check(a b c d e f g h,19)) {
for (i=0; i<10; i++) if (check(a b c d e f g h i,23)) {
for (j=0; j<10; j++) if (check(a b c d e f g h i j,29)) {
print a b c d e f g h i j;
}
}
}
}
}
}
}
}
}
}
}
function check(nnn,pp) {
nnn += 0
return ((nnn % pp) == 0);
}
Edited on January 4, 2005, 5:24 pm