I read in Malcom Line’s book (thanks, Google Book Search!) a nice discussion of repeating digit primes. It goes like this.
We know that 11 is a prime number. Are there any other primes with only a single repeating digit, i.e., of the form 111…11? Since 11*101=1111, 1111*101=111111 (six digits), we can see that any even length repeating digit number is not a prime. Likewise, since 111 is not prime, neither is 111111111 (nine digits) or any number with 3n digits, since we can use a construction like 111111*1001001=111111111. Using this line of reasoning we can see that any repeating digit number whose length is not prime cannot be prime either. So that leaves only prime lengths. We know by using MATLAB’s “factor” command that (using monetary notation to group digits into thousands)
11,111 = 41*271 % 5 digits is not prime
1,111,111 = 239*4,629 % neither is 7 digits
The “factor” command is limited to 2^32, or 10 digits, which is not enough for the 11 digit repeater. However, we can write a simple MATLAB script to find that
11,111,111,111 = 21,649 * 513,239
Similarly, we can find that the 13 digit repeater factors into three primes
1,111,111,111,111 = 53 * 79 * 26,5371,653
The 17 digit repeater requires more work, since it exceeds the 4 byte integer math capability of MATLAB. We have to devise a long division routine. We can take advantage of the 15 digit precision of a IEEE 754 “double”, which MATLAB uses for floating point calculations, and divide the 17 digit string starting from the left most 15 digits. This gives
11,111,111,111,111,111 = 2,071,723 * 10,726,419,557
One way to check this is to use the “multiplystrings” script below.
How about the 19 digit repeater? It is said to be prime in Lines’s book (see above). I don’t have a script to check it yet, though I know it has no prime factors with less than 9 digits. If you know of a good primality script in matlab or octave, please let me know.