I am trying to write a code to calculate, for a given prime p the string length k of the repunit
R_k=1111111....1111 (with k 1s) such that the number R_kpR_k is prime.
Example: If p=59, then k=42 is the smallest k such that R_k59R_k is prime. Note that for some primes it can be shown that no such k exists (2,11,37,101..)
I can usually figure out from the factor cycle of a “repunit wrapped” prime whether such a k exists or not. But if the indications are that a k does exist then finding it is very time consuming. Eg for p =71, 167.
What i want to do, for given p is set an upper limit N for k then check to see if R_kpR_k is prime for values of k from 1 to N
The bit I can’t handle is expressing the “wrapped” number for a given p and k, and also indexing from k to k+1, until N is reached or a prime found.
Any assistance gratefully received.