Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #21 Mar 06 2023 08:02:33
%S 2,5,3,17,0,13,11,0,7,5,3,97,23,0,19,17,0,13,11,0,7,5,3,73,71,0,67,
%T 113,0,61,59,0,103,53,0,97,47,0,43,41,0,37,83,0,31,29,0,73,23,0,19,17,
%U 0,13,11,0,7,5,3,241,47,0,43,41,0,37,227,0,31,29,0,0,23,0,19,17
%N Smallest prime p such that 2n+p is the square of a prime, or 0 if no such prime exists.
%C Many of the zeros can be understood: Let p = q^2-2*n, for q prime. q <= 3 only leads to positive p for n <= 4. For n > 4, q > 3 so q^2 mod 3 = 1, and if n = 2 mod 3 then p = 0 mod 3, so p is either 3 or a multiple of 3. Thus for n > 4 with n = 2 mod 3, a(n) = 3 or 0, and instances of 3 should become increasingly rare at large n. Not all zeros are of this form: when 2*n is a square, k^2, then (q^2-2*n)=(q-k)*(q+k) and p cannot be prime unless q-k=1. n=72=(12^2/2) is the first case for which a(n) = 0 and n is not congruent to 2 mod 3. Possibly all zeros fall into one of these two categories (all those for n<=10^5 do). - _D. S. McNeil_, Nov 24 2010
%H Michel Marcus, <a href="/A109619/b109619.txt">Table of n, a(n) for n = 1..10000</a>
%e For n=4, we find that 17+2*4=25=5^2 and no smaller prime than 17 works, so a(4)=17.
%e For n=5, the 2 mod 3 argument applies and a(5)=3 or 0; but 3+2*5=13 which is not a squared prime, so a(5)=0.
%o (PARI) b(n) = my(q); forprime(p=1, 200000, if (issquare(p+2*n, &q) && isprime(q), return(p))); \\ eventually to check a(n)
%o findp(n) = forprime(p=2, , if (issquare(p+2*n, &q) && isprime(q), return(p)));
%o a(n) = if (n <= 4, return(findp(n))); my(m = n % 3, k); if ((m == 2), if (issquare(2*n+3, &q) && isprime(q), return(3), return(0))); if (m == 0, if (issquare(2*n, &k), if (!isprime(1+k) || !isprime((1+k)^2-2*n), return(0)););); findp(n); \\ _Michel Marcus_, Mar 06 2023
%K nonn,look
%O 1,1
%A _John W. Layman_, Aug 01 2005
%E Extended and correctness proved by _D. S. McNeil_, Nov 24 2010
%E More terms from _Michel Marcus_, Mar 06 2023