OFFSET
1,7
COMMENTS
Find the number (the "run length") of successive intervals [p, p'=nextprime(p)] (followed by [p', p''], then [p'', p'''] etc.) which do not contain a square. When a square (n+1)^2 is found in such an interval, this will result in a term a(2n) = 0, preceded by a(2n-1) = the number of intervals of primes counted before reaching that square, i.e., between n^2 and (n+1)^2. - M. F. Hasler, Oct 01 2018
LINKS
Vincenzo Librandi, Table of n, a(n) for n = 1..10000
FORMULA
a(2n) = 0: this is the interval from the greatest prime less than the (n+1)th square, through that square and up to the least prime greater than that square. - Robert G. Wilson v, Apr 23 2005
a(2n-1) = the difference between the indices of the greatest prime less than (n+1)^2 and the least prime greater than n^2. - Robert G. Wilson v, Apr 23 2005
a(2n-1) = A014085(n) - 1 = primepi((n+1)^2) - primepi(n^2) - 1. - M. F. Hasler, Oct 01 2018
EXAMPLE
a(1)=1 because the first interval between primes (2 to 3) is free of squares.
a(2)=0 because there is a square between 3 and 5.
a(7)=2 because there are two successive squarefree intervals: 17 to 19; and 19 to 23.
a(8)=0 because between 23 and 29 there is a square: 25.
MATHEMATICA
NextPrim[n_] := Block[{k = n + 1}, While[ !PrimeQ[k], k++ ]; k]; PrevPrim[n_] := Block[{k = n - 1}, While[ !PrimeQ[k], k-- ]; k]; f[n_] := If[ EvenQ[n], 0, PrimePi[ PrevPrim[(n + 3)^2/4]] - PrimePi[ NextPrim[(n + 1)^2/4]]]; Table[ f[n], {n, 100}] (* Robert G. Wilson v, Apr 23 2005 *)
PROG
(PARI) p=2; c=0; forprime(np=p+1, 1e4, if( sqrtint(p) < sqrtint(np), print1(c", ", c=0, ", "), c++); p=np) \\ For illustrative purpose. Better:
A104477(n)=if(bittest(n, 0), primepi((1+n\/=2)^2)-primepi(n^2)-1, 0) \\ M. F. Hasler, Oct 01 2018
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Alexandre Wajnberg, Apr 18 2005
EXTENSIONS
More terms from Robert G. Wilson v, Apr 23 2005
Offset corrected by M. F. Hasler, Oct 01 2018
STATUS
approved