%I #57 Oct 12 2023 07:47:04
%S 11,11,1114111,111181111,111110611111,1111118111111,111111151111111,
%T 111111110911111111,1111111111111111111,1111111111111111111,
%U 1111111111111111111,1111111111111111111,1111111111111111111,1111111111111111111,1111111111111111111,1111111111111111111,1111111111111111111
%N a(n) is the first prime that starts and ends with at least n 1's (in base 10).
%C The initial and final strings of 1's are allowed to overlap.
%C If k is in A004023 and (k+1)/2 <= j <= k, then a(j) = (10^k-1)/9 (unless it is (10^i-1)/9 for some i < k where i is in A004023 and (i+1)/2 <= j <= i).
%H Robert Israel, <a href="/A366416/b366416.txt">Table of n, a(n) for n = 1..495</a>
%H S. Dutta et al, <a href="https://math.stackexchange.com/questions/4784494/infinitely-many-primes-of-the-form-underbrace11-dots-1-k-text-times-dot">Infinitely many primes of the form 11...1 (k times) ... 11 ... 1 (k times</a>, Mathematics StackExchange
%e a(3) = 1114111 which is prime and starts and ends with 3 1's.
%p f:= proc(n) local x,s,d;
%p for d from n to 2*n-1 do
%p if isprime((10^d-1)/9) then return (10^d-1)/9 fi
%p od;
%p s:= (10^n-1)/9;
%p for d from n do
%p for x from 10^d*s + s by 10^n to 10^d*(s+1) do
%p if isprime(x) then return x fi
%p od od
%p end proc:
%p map(f, [$1..20]);
%o (Python)
%o from gmpy2 import is_prime
%o def a(n):
%o t = (10**n-1)//9
%o for d in range(n, 2*n):
%o if is_prime(t): return t
%o t = 10*t + 1
%o suffix = (10**n-1)//9
%o d = 2*n
%o while True:
%o prefix = 10**(d-n)*suffix
%o for mid in range(0,10**(d-n),10**n):
%o t = prefix + mid + suffix
%o if is_prime(t): return t
%o d += 1
%o print([a(n) for n in range(1,18)]) # _Michael S. Branicky_, Oct 10 2023
%Y Cf. A004023, A068160.
%K nonn,base,look
%O 1,1
%A _Robert Israel_, Oct 10 2023