login
A127356
a(n) is the smallest k > 0 such that k^2 + prime(n) is prime.
4
1, 2, 6, 2, 6, 2, 6, 2, 6, 12, 4, 2, 24, 2, 6, 6, 18, 6, 2, 6, 4, 2, 12, 12, 2, 6, 2, 12, 2, 6, 2, 6, 6, 10, 12, 4, 4, 2, 12, 12, 18, 4, 6, 2, 6, 8, 4, 2, 6, 2, 6, 12, 4, 24, 6, 18, 18, 6, 2, 6, 8, 18, 2, 6, 2, 6, 4, 4, 6, 2, 6, 12, 4, 4, 2, 6, 30, 2, 24, 10
OFFSET
1,2
COMMENTS
All terms apart from the first need to be even because all primes but the first one have the same parity. Record values 1, 2, 6, 12, 24, 30, 42, 54, 60, 66, 90, 132, 138, 210, 270, ... are set at n=1, 2, 3, 10, 13, 77, 92, 152, 294, 484, 517, 964, 1203, 2876, 14118, ... - R. J. Mathar, Apr 02 2007
a(n) exists for all n on the Hardy-Littlewood conjecture F. - Charles R Greathouse IV, Jul 26 2012
EXAMPLE
17 = prime(7); 17 + 1^2 = 18, 17 + 2^2 = 21, 17 + 3^2 = 26, 17 + 4^2 = 33, 17 + 5^2 = 42 are all composite, but 17 + 6^2 = 53 is prime. Hence a(7) = 6.
MAPLE
a:=proc(n) local A, j: A:={}: for j from 1 to 50 do if isprime(ithprime(n)+j^2)=true then A:=A union {j} else A:=A fi od: A[1]: end: seq(a(n), n=1..120); # Emeric Deutsch, Apr 01 2007
A127356 := proc(n) local p, a; p := ithprime(n) ; a := 1 ; while not isprime(p+a^2) do a := a+1 ; od ; RETURN(a) ; end: for n from 1 to 120 do printf("%d, ", A127356(n)) ; od ; # R. J. Mathar, Apr 02 2007
MATHEMATICA
Join[{1}, Table[p=Prime[n]; x=2; While[!PrimeQ[a=p+x^2], x=x+2]; x, {n, 2, 100}]] (* Zak Seidov, Oct 12 2012 *)
sk[n_]:=Module[{k=2}, While[!PrimeQ[n+k^2], k=k+2]; k]; Join[{1}, Table[sk[n], {n, Prime[Range[2, 80]]}]] (* Harvey P. Dale, Jul 26 2017 *)
PROG
(PARI) {for(n=1, 93, p=prime(n); k=1; while(!isprime(p+k^2), k++); print1(k, ", "))} /* Klaus Brockhaus, Apr 05 2007 */
(Python)
from sympy import isprime, nextprime, prime
def a(n):
if n == 1: return 1
k, pn = 2, prime(n)
while not isprime(pn + k*k): k += 2
return k
print([a(n) for n in range(1, 81)]) # Michael S. Branicky, Nov 11 2022
CROSSREFS
Cf. A000040 (the primes), A000290 (the squares).
Sequence in context: A011325 A010696 A021796 * A232273 A307892 A276152
KEYWORD
nonn
AUTHOR
J. M. Bergot, Mar 30 2007
EXTENSIONS
Edited, corrected and extended by Emeric Deutsch, R. J. Mathar and Klaus Brockhaus, Apr 01 2007
STATUS
approved