A359300 a(n) = (distance from n to nearest prime >= n) - (distance from n to nearest prime <= n).
0, 0, 0, 0, 0, 0, 2, 0, -2, 0, 0, 0, 2, 0, -2, 0, 0, 0, 2, 0, -2, 0, 4, 2, 0, -2, -4, 0, 0, 0, 4, 2, 0, -2, -4, 0, 2, 0, -2, 0, 0, 0, 2, 0, -2, 0, 4, 2, 0, -2, -4, 0, 4, 2, 0, -2, -4, 0, 0, 0, 4, 2, 0, -2, -4, 0, 2, 0, -2, 0, 0, 0, 4, 2, 0, -2, -4, 0, 2, 0
Offset: 2
Keywords
Examples
a(8) = 2 because (11-8) - (8-7) = 2.
Programs
-
Maple
f:= n -> nextprime(n-1) + prevprime(n+1) - 2*n: map(f, [$2..100]); # Robert Israel, Jan 03 2023
-
Mathematica
u[n_] := If[PrimeQ[n], n, NextPrime[n]]; v[n_] := If[PrimeQ[n], n, NextPrime[n, -1]]; Table[u[n] - n - (n - v[n]), {n, 2, 350}]
Comments