login
a(1)=1, a(n) = smallest positive integer not included earlier such that the n-th partial sum is a prime iff n is a prime.
3

%I #11 Oct 08 2024 07:25:28

%S 1,2,4,3,7,5,9,8,6,10,12,11,19,13,14,16,17,15,21,20,18,22,24,23,25,26,

%T 27,28,33,29,31,30,32,34,35,36,43,37,38,40,39,41,49,42,45,44,67,46,47,

%U 48,50,51,54,53,52,56,57,55,63,58,60,59,61,64,62,65,69,68,66,70,72,71

%N a(1)=1, a(n) = smallest positive integer not included earlier such that the n-th partial sum is a prime iff n is a prime.

%H Robert Israel, <a href="/A073885/b073885.txt">Table of n, a(n) for n = 1..10000</a>

%p S:= [$2..200]: # stop before the first term > 200

%p s:= 1: R:= 1:

%p for i from 2 do

%p target:= isprime(i);

%p found:= false;

%p for j from 1 to nops(S) while not found do

%p if isprime(s+S[j]) = target then

%p found:= true;

%p R:= R,S[j];

%p s:= s+S[j];

%p S:= subsop(j=NULL,S);

%p fi

%p od;

%p if not found then break fi;

%p od:

%p R; # _Robert Israel_, Oct 07 2024

%t For[n=1; s={}; sum=0, n<=100, n++, For[v=1, MemberQ[s, v]||Xor[PrimeQ[n], PrimeQ[sum+v]], v++, Null]; sum+=v; AppendTo[s, a[n]=v]]; a/@Range[100]

%Y Cf. A073886.

%K nonn

%O 1,2

%A _Amarnath Murthy_, Aug 17 2002

%E Edited by _Dean Hickerson_, Oct 22 2002