OFFSET
1,2
LINKS
Robert Israel, Table of n, a(n) for n = 1..10000
EXAMPLE
n = 4 is even, 5 is the least number not occurring earlier that makes fourth partial sum prime: 1+2+3+5 = 11. n = 5 is odd, 4 is the least number not occurring earlier that makes fifth partial sum nonprime: 1+2+3+5+4 = 15.
MAPLE
N:= 100: # terms until the first term > N
R:= NULL: S:= [$1..N]: s:= 0: found:= true;
for n from 1 while found do
found:= false;
for i from 1 to nops(S) do
if isprime(S[i]+s) xor n::odd then
found:= true; R:= R, S[i]; s:= s + S[i]; S:= subsop(i=NULL, S); break
fi
od od:
R; # Robert Israel, Sep 13 2020
MATHEMATICA
Module[{n, m = 72, s = 0, v = {}}, Reap[For[n = 1, n <= m, n++, k = 1; While[MemberQ[v, k] || PrimeQ[s+k] != EvenQ[n], k++]; Sow[k]; s = s+k; v = Union[v, {k}]]][[2, 1]]] (* Jean-François Alcover, Nov 03 2020, after PARI *)
PROG
(PARI) {m=72; s=0; v=Set([]); for(n=1, m, k=1; while(setsearch(v, k)>0||isprime(s+k)!=(n%2==0), k++); print1(k, ", "); s=s+k; v=setunion(v, Set(k)))}
CROSSREFS
KEYWORD
nonn
AUTHOR
Amarnath Murthy, Jun 20 2004
EXTENSIONS
Edited, corrected and extended by Klaus Brockhaus, Jun 21 2004
STATUS
approved