OFFSET
1,1
COMMENTS
If n is prime a(n) = n, If n is not a prime but 2n+1 is a prime then a(n) = 2n+1 else a(n) = 0, as the difference of two triangular numbers is composite if the indices differ by more than 2. r(r+1)/2 - s(s+1)/2 is composite if r-s >2.
LINKS
R. J. Mathar, Table of n, a(n) for n = 1..1000
MAPLE
A089306 := proc(n)
local k;
if not isprime(n) and not isprime(2*n+1) then
return 0 ;
end if;
for k from 0 do
p := (k+1)*(k+2*n)/2 ;
if isprime(p) then
return p;
end if;
end do:
end proc; # R. J. Mathar, Jun 06 2013
MATHEMATICA
a[n_] := Module[{k}, If[!PrimeQ[n] && !PrimeQ[2n+1], Return[0]]; For[k = 0, True, k++, p = (k+1)(k+2n)/2; If[PrimeQ[p], Return[p]]]];
Array[a, 100] (* Jean-François Alcover, Mar 25 2020, after R. J. Mathar *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Amarnath Murthy, Nov 01 2003
EXTENSIONS
More terms from David Wasserman, Sep 09 2005
STATUS
approved