xint pandigit_mul_concat(xint n) { xint i=1; xint p=0; while ( !pandigital1to9_p(p) && digits_in(p)<10 ) { xint next = n * i; if ( p>0 ) p *= power(10, digits_in(next)); p += next; ++i; } return p; }
int main() { xint max = 0; for ( xint n=1; ; ++n ) { xint p = pandigit_mul_concat(n); if ( !pandigital1to9_p(p) || digits_in(p) > 9 ) continue; if ( digits_in(n) > 4 ) break; if ( p > max ) { max = p; printf("-- %s for n=%s\n", str(max), str(n)); } } printf("end\n"); }
int digits_in(int num) { if (num == 0) { return 1; // log10() chokes on 0 } if (num < 0) { return 1 + digits_in(0 - num); // 1 extra for the - character } return 1 + log10(num); // 1 extra since log10 is logarythmic }