A377090 a(0) = 0; thereafter, for n > 0, a(n) is the least integer (in absolute value) not yet in the sequence such that the absolute difference between a(n-1) and a(n) is a prime number; in case of a tie, preference is given to the positive value.
0, 2, -1, 1, -2, 3, -4, -6, -3, 4, 6, -5, -7, -9, 8, 5, 7, 9, -8, -10, -12, 11, 13, 10, 12, -11, -13, -15, 14, 16, 18, 15, -14, -16, -18, 19, 17, 20, -17, -19, -21, 22, 24, 21, -20, -22, -24, 23, 25, 27, -26, -23, -25, -27, 26, 28, 30, -29, -31, -28, -30, 29
Offset: 0
Examples
The first terms are: n a(n) |a(n)-a(n-1)| --- ------ ------------- 0 0 N/A 1 2 2 2 -1 3 3 1 2 4 -2 3 5 3 5 6 -4 7 7 -6 2 8 -3 3 9 4 7 10 6 2 11 -5 11 12 -7 2 13 -9 2 14 8 17
Links
- Paolo Xausa, Table of n, a(n) for n = 0..10000 (terms 0..1000 from Rémy Sigrist).
- Rémy Sigrist, Scatterplot of the first 100000 terms of the partial sums
- Rémy Sigrist, PARI program
Crossrefs
Programs
-
Mathematica
A377090list[nmax_] := Module[{s, a, u = 1}, s[_] := False; s[0] = True; NestList[(While[s[u] && s[-u], u++]; a = u; While[s[a] || !PrimeQ[Abs[# - a]], a = Boole[a < 0] - a]; s[a] = True; a) &, 0,nmax]]; A377090list[100] (* Paolo Xausa, Mar 27 2025 *)
-
PARI
\\ See Links section.
-
PARI
A377090_first(N, L=1, U=[])={vector(N, n, while(setsearch(U,L), U=setminus(U,[L]); L=(L<0)-L); N=if(n>1, n=L; while(!isprime(abs(n-N)) || setsearch(U, n), n=(n<0)-n); U=setunion(U, [n]); n))} \\ M. F. Hasler, Feb 21 2025
-
Python
from sympy import isprime from itertools import count, islice def cond(n): return isprime(n) def agen(): # generator of terms an, aset, m = 0, {0}, 1 for n in count(0): yield an an = next(s for k in count(m) for s in [k, -k] if s not in aset and cond(abs(an-s))) aset.add(an) while m in aset and -m in aset: m += 1 print(list(islice(agen(), 62))) # Michael S. Branicky, Dec 27 2024
-
Python
from sympy import isprime def A377090(n): while len(terms := A377090.terms) <= n: while (k := A377090.N) in terms: A377090.N = (k<0)-k while not isprime(abs(k - terms[-1])) or k in terms: k = (k<0)-k terms.append(k) return terms[n] A377090.terms = [0]; A377090.N = 1 # least unused candidate # M. F. Hasler, Feb 10 2025, simplified Feb 15 2025
Formula
||a(n)| - n/2| = O(log(n)), probably ||a(n)| - n/2| < 2 log(n+2) for all n. (Conjectured; verified up to n = 10^5.) - M. F. Hasler, Feb 21 2025
Comments