A near-repdigit number is a positive integer where all the digits are the same, except one. For example 101 and 227 are near-repdigits. A near-repdigit prime is a near-repdigit that is also prime. For example:
101, 113, 131, 151, 181, 191, 199, 211, 223, 227, 229, 233, 277, 311, 313, 331, 337, 353, 373, 383, 433, 443, 449, 499, 557, 577, 599, 661, 677, 727, 733, 757, 773, 787, 797, 811, 877, 881, 883, 887, 911, 919, 929, 977, 991, 997, 1117, 1151, 1171, 1181, 1511
These are all near-repdigit primes.
The smallest near-repdigit prime has two digits, but it is an open mathematical question whether there exists a near-repdigit prime for every possible number of digits larger than 2. It is conjectured, by me, that the answer is in fact yes.
Task
For each integer n
where n >= 2
, compute a near-repdigit prime with n
digits.
Your code can either output a near-repdigit prime with 2, 3, ... digits or, as they are easily compressible, output a compressed representation of each number. For example, any near-repdigit can be represented by four smaller numbers. The first is the number of digits, the second the majority digit, the third the minority digit and the fourth the location of the minority digit. You can choose whichever representation you prefer.
Primality testing
There are many different ways to test if a number is prime. You can choose any method subject to the following conditions.
- You can use any primality test that is guaranteed never to make a mistake.
- You can use any well-known primality test which hasn't been proved to be correct but for which there is no known example number for which it gives the wrong answer.
- You can use a probabilistic primality test if the probability of giving the wrong answer is less than 1/1000.
I will test your code for 5 minutes on my ubuntu 22.04 machine, but please quote how high you get on your machine in your answer.
This challenge is judged per language.
In the very unlikely event that you find a number of digits n for which there is no near-repdigit prime, I will award a 500-rep bounty and you will get mathematical immortality.
Results so far
- n=1291 by Kirill L. in Julia
- n=1291 by c-- in C with gmp
- n=1232 by jdt in C++ with gmp
- n=972 by Kirill L. in Julia
- n=851 by alephalpha in Pari/GP
- n=770 by ZaMoC in Wolfram Language (not tested on my PC)
- n=722 by gsitcia in Pypy/Python
- n=721 by jdt in C++
- n=665 by c-- in C++
- n=575 by Seggan in Kotlin
- n=403 by Arnauld in nodejs
- n=9 by py3_and_c_programmer in Python