Prime numbers are prime no matter what base they are represented in.

A prime number in a base other than 10 may not look prime at first glance.

For instance: 19 base 10 is 25 in base 7.



Several different prime numbers may be expressed as the "same" string when converted to a different base.

 107 base 10 converted to base 6 == 255
 173 base 10 converted to base 8 == 255
 353 base 10 converted to base 12 == 255
 467 base 10 converted to base 14 == 255
 743 base 10 converted to base 18 == 255
 1277 base 10 converted to base 24 == 255
 1487 base 10 converted to base 26 == 255
 2213 base 10 converted to base 32 == 255


Task
Restricted to bases 2 through 36; find the strings that have the most different bases that evaluate to that string when converting prime numbers to a base.

Find the conversion string, the amount of bases that evaluate a prime to that string and the enumeration of bases that evaluate a prime to that string.

Display here, on this page, the string, the count and the list for all of the: 1 character, 2 character, 3 character, and 4 character strings that have the maximum base count that evaluate to that string.

Should be no surprise, the string '2' has the largest base count for single character strings.



Stretch goal
Do the same for the maximum 5 character string.



use strict;
use warnings;
use feature 'say';
use List::AllUtils <firstidx max>;
use ntheory qw/fromdigits todigitstring primes/;
 
my(%prime_base, %max_bases, $l);
 
my $chars  = 5;
my $upto   = fromdigits( '1' . 'Z' x $chars, 36);
my @primes = @{primes( $upto )};
 
for my $base (2..36) {
    my $n = todigitstring($base-1, $base) x $chars;
    my $threshold = fromdigits($n, $base);
    my $i = firstidx { $_ > $threshold } @primes;
    map { push @{$prime_base{ todigitstring($primes[$_],$base) }}, $base } 0..$i-1;
}
 
$l = length and $max_bases{$l} = max( $#{$prime_base{$_}}, $max_bases{$l} // 0 ) for keys %prime_base;
 
for my $m (1 .. $chars) {
    say "$m character strings that are prime in maximum bases: ", 1+$max_bases{$m};
    for (sort grep { length($_) ==  $m } keys %prime_base) {
        my @bases = @{($prime_base{$_})[0]};
        say "$_: " . join ' ', @bases if $max_bases{$m} eq $#bases;
    }
    say ''
}