OFFSET
1,2
COMMENTS
LINKS
Giovanni Resta, Table of n, a(n) for n = 1..10000
EXAMPLE
List the numbers with an increment of 1 beginning at n=1, and stop when the number of numbers reaches a prime, in this case the list would be {1,2} since its size is 2. Find the number of primes in that interval and add it to the sequence. In this case, there is 1 prime in the list. Continue counting from the last number in the previous list and apply the same rules, the next list will be {3,4,5} of size 3 and contains 2 prime numbers. The list after that will be {6,7,8,9,10} of size 5 and contains 1 prime number.
MATHEMATICA
numberOfLines = 100; (*How many elements desired in the sequence*) a = {0}; distribution = {}; last = 0; For[j = 1, j <= numberOfLines, j++, frequency = 0; b = {}; For[i = 1, i <= Prime[j], i++, b = Append[b, last + i]; If[PrimeQ[b[[i]]], frequency += 1]; ]; last += Prime[j]; distribution = Append[distribution, frequency]; ]; Print["Distribution = ", distribution]; ListPlot[distribution]; (*original program*)
seq[n_] := Block[{a=0, b=2, p=2, v}, Table[v = PrimePi@b-PrimePi@a; p = NextPrime@p; a = b; b += p; v, {n}]]; seq[100] (* faster version, Giovanni Resta, May 18 2013 *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Victor Phan, May 17 2013
STATUS
approved