%I #21 Jan 04 2022 04:09:08
%S 3,2,3,19,5,41,3,19,11,67,5,131,13,41,17,101,17,37,11,29,109,47,5,101,
%T 53,1619,13,173,11,311,31,23,103,181,19,149,37,53,41,491,13,947,23,71,
%U 137,659,7,97,151,67,131,953,53,131,41,151,59,353,11,487,61,127,191,79,43,4021,67,139,29
%N a(n) is the least prime p such that p^2+n = q*(n+1) for some prime q.
%C a(n) >= sqrt(n+2), with equality if and only if n+2 is the square of a prime.
%H Robert Israel, <a href="/A350517/b350517.txt">Table of n, a(n) for n = 1..10000</a>
%F a(n)^2+n = (n+1)*A350518(n).
%e a(4) = 19 because 19 is prime and 19^2+4 = 365 = 73*(4+1) where 73 is prime, and no smaller prime than 19 works.
%p g:= proc(n) local p,M,a,m,q;
%p M:= sort(map(t -> rhs(op(t)), [msolve(p^2=1, n+1)]));
%p for a from 0 do
%p for m in M do
%p p:= a*(n+1)+m;
%p if not isprime(p) then next fi;
%p q:= (p^2+n)/(n+1);
%p if isprime(q) then return p fi
%p od od:
%p end proc:
%p map(g, [$1..100]);
%t a[n_] := Module[{p = NextPrime[Floor[Sqrt[n + 2]] - 1], q}, While[! IntegerQ [(q = (p^2 + n)/(n + 1))] || ! PrimeQ[q], p = NextPrime[p]]; p]; Array[a, 70] (* _Amiram Eldar_, Jan 03 2022 *)
%o (PARI) isp(r) = (denominator(r)==1) && isprime(r);
%o a(n) = my(p=2); while (!isp((p^2+n)/(n+1)), p = nextprime(p+1)); p; \\ _Michel Marcus_, Jan 03 2022
%o (Python)
%o from sympy import isprime, nextprime
%o def A350517(n):
%o p = 2
%o while True:
%o a, b = divmod(p**2+n,n+1)
%o if not b and isprime(a):
%o return p
%o p = nextprime(p) # _Chai Wah Wu_, Jan 04 2022
%Y Cf. A350518.
%K nonn
%O 1,1
%A _J. M. Bergot_ and _Robert Israel_, Jan 02 2022