login
A377090
a(0) = 0, and for any n > 0, a(n) is the least integer (in absolute value) not yet in the sequence such that the absolute difference of a(n-1) and a(n) is a prime number; in case of a tie, preference is given to the positive value.
6
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,2
COMMENTS
This sequence is a variant of A277618 allowing negative values.
Will every integer appear in the sequence?
The distances d(n) = |a(n)| - n/2 remain very small: Records of |d(n)| appear at
d(1) = 1.5, d(7) = 2.5, d(30) = 3.0, d(117) = 3.5, d(124) = -4.0, d(326) = -5.0,
d(530) = 6.0, d(1137) = 6.5, d(1142) = -7.0, d(1342) = 8.0, d(5363) = 8.5,
d(5370) = -9.0, d(9567) = 9.5, d(9568) = 10.0, ... - M. F. Hasler, Feb 10 2025
LINKS
Paolo Xausa, Table of n, a(n) for n = 0..10000 (terms 0..1000 from Rémy Sigrist).
Rémy Sigrist, PARI program
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
EXAMPLE
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
MATHEMATICA
A377090list[nmax_] := Module[{s, a = 0, an, u = 1}, s[_] := False; s[0] = True; Join[{0}, Table[a = (While[s[u] && s[-u], u++]; an = u; While[s[an] || !PrimeQ[Abs[a - an]], an = Boole[an < 0] - an]; s[an] = True; an), nmax]]];
A377090list[100] (* Paolo Xausa, Jan 20 2025 *)
PROG
(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
CROSSREFS
Cf. A277618, A377091, A377092, A380311 (partial sums).
Sequence in context: A030737 A238587 A320767 * A058713 A331564 A288250
KEYWORD
sign,look,changed
AUTHOR
Rémy Sigrist, Oct 16 2024
STATUS
approved