## Minimax Pandigital Factor

### June 13, 2014

Over at /r/math, Darksteve writes of “A problem I came up with, and haven’t been able to solve for many years:”

I would like to present a mathematical problem that I came up with some years ago, and haven’t yet found a solution for:

If you take all the numbers that contain the digits 1 to 9 exactly once, and you write down the prime factorization of all those numbers, which one has the smallest biggest prime factor?

To illustrate what I mean, the number 879456123 contains the prime factors 3 7 13 and 491; making 491 this numbers biggest prime factor.

The number 213456789 contains 3 7 13 and 197 as factors, making 197 the biggest prime factor. Out of all the numbers I’ve tried, 213456789 has the smallest biggest prime factor.

Many other number have much bigger biggest prime factors, like 576492813 which contains 3 13 19 and 13649.

But I have not found a way to actually solve this problem, as I am lacking the programming skills, or the algebraic knowledge required. I would therefore greatly appreciate anyone capable of solving this.

Your task is to solve Darksteve’s problem. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

In Python. I used the factorization method in the PP Primes Essay.

Build up list of numbers with std::next_permutation, then pull out factors from the bottom until some are reduced to 1:

Perl using modules:

use Algorithm::Combinatorics qw/permutations/;

use Math::Prime::Util qw/factor/;

my $small = [1e12, 0];

my $it = permutations([qw/1 2 3 4 5 6 7 8 9/]);

while (my $p = $it->next) {

my $n = join(“”,@$p);

my $bf = (factor($n))[-1]; # take largest factor

$small = [$bf, $n] if $bf [0];

}

print “Smallest largest factor is $small->[0] of number $small->[1]\n”;

To clarify, since I am not sure I understand the problem completely. The problem is trying to identify pandigital numbers who largest factor is smaller than some limit L?

The task is to calculate the largest factor of each pandigital number, and find the smallest of those. Thus, the number 483761925 = 3^2 * 5^2 * 523 * 4111 is pandigital and its largest factor is 4111. But 4111 is not the smallest largest factor, because the largest factor of 483761952 = 2^5 * 3^2 * 41 * 53 * 773 is smaller. In fact, the smallest largest factor is 7, which appears in two different pandigital numbers: 619573248 = 2^12 * 3^2 * 7^5 and 948721536 = 2^7 * 3^2 * 7^7.

Ah, now I understand. I really enjoyed your solution @matthew. Here is a different Perl solution (doesn’t display ties):

@mcmillhj: Thank you, most kind.

Another Python solution.

Actually solved this one straight in the Scala REPL, with pandigitals and prime factors functions I already have in my standard “puzzles” library. Kind of brute forced, but it only took around 3 seconds to run.