OFFSET
1,1
COMMENTS
It appears that a(n) = n occurs only for n=3, 7, 13. It also appears that a(n+1) is never equal to a(n).
The list of indices such that a(n)=1 correspond to the primes in A053845. - Michel Marcus, Apr 16 2015
In other words, a(n) = prime(n) - A007504(k) for largest k such that prime(n) > A007504(k). - Danny Rorabaugh, Apr 20 2015
LINKS
Charles R Greathouse IV, Table of n, a(n) for n = 1..10000
FORMULA
a(n) << sqrt(n)*log(n). - Charles R Greathouse IV, Apr 23 2015
EXAMPLE
a(1) = 2, since there is no previous prime.
a(2) = 1, since 3 - 2 = 1.
a(3) = 3, since 5 - 2 = 3.
a(4) = 2, since 7 - 2 - 3 = 2.
a(5) = 1, since 11 - 2 - 3 - 5 = 1.
a(6) = 3, since 13 - 2 - 3 - 5 = 3.
a(13) = 13, since 41 - 2 - 3 - 5 - 7 - 11 = 13.
MATHEMATICA
lst = {}; i = 1; While[i <= 1000, x = Prime[i]; k = 1; While[x > 0, x -= Prime[k]; k++]; x += Prime[k - 1]; AppendTo[lst, x]; i++]; lst
PROG
(PARI) a(n) = {s = prime(n); k = 1; while ((ns = (s - prime(k))) > 0, s = ns; k++); s; } \\ Michel Marcus, Apr 16 2015
(PARI) s=0; q=2; forprime(p=2, 10, if(s+q>p, s+=q; q=nextprime(q+1)); print1(p-s", ")) \\ Charles R Greathouse IV, Apr 22 2015
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Carlos Eduardo Olivieri, Apr 15 2015
STATUS
approved