OFFSET
1,2
COMMENTS
Previous name was: Starting with n+(n-1) go on adding n-2, then n-3, etc. until one gets a prime; a(n) = smallest prime in n+(n-1)+(n-2)+...+(n-i) (with the least i that gives a prime), or 0 if no such prime exists.
LINKS
Harvey P. Dale, Table of n, a(n) for n = 1..1000
FORMULA
If 2n-1 is prime then a(n) = 2n-1, otherwise a(n) = 0. - David Wasserman, Jan 25 2005
a(n+1) = (4n-1)!! mod (2n+1)^2; by Gauss generalization of the Wilson's theorem. - Thomas Ordowski, Jul 23 2016
EXAMPLE
a(8) = 0 as there is no prime in the partial sum of the finite sequence 8,7,6,5,4,3,2,1.
a(7) = 13 = 7 + 6.
MATHEMATICA
apr[n_]:=Module[{cl=Select[Rest[Accumulate[Range[n, 1, -1]]], PrimeQ, 1]}, If[cl=={}, 0, First[cl]]]; Array[apr, 100] (* Harvey P. Dale, Jun 01 2012 *)
b[n_] := Mod[(-5 + 4 n)!!, (-1 + 2 n)^2]; a = Array[b, 82] (* Fred Daniel Kline, Oct 04 2018; Thomas Ordowski's formula with adjusted index *)
PROG
(PARI) a(n) = if (isprime(p=2*n-1), p, 0); \\ Michel Marcus, Aug 09 2018
(Magma) DoubleFactorial:=func< n | &*[n..2 by -2] >; [ DoubleFactorial(-5 + 4*n) mod (-1 + 2*n)^2: n in [1..90]]; // Vincenzo Librandi, Oct 04 2018
(Magma) [IsPrime(2*n-1) select 2*n-1 else 0: n in [1..90]]; // Bruno Berselli, Oct 05 2018
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Amarnath Murthy and Meenakshi Srikanth (menakan_s(AT)yahoo.com), Jul 02 2003
EXTENSIONS
More terms from David Wasserman, Jan 25 2005
New name using formula from David Wasserman, Joerg Arndt, Jul 24 2016
STATUS
approved