A373805 If a(n-1) is not a prime, then a(n) = 2*a(n-1) + S; otherwise set S = -S and a(n) = prime(n) + S; start with a(1) = S = 1.
1, 3, 4, 7, 12, 25, 51, 103, 22, 43, 32, 65, 131, 42, 83, 54, 109, 60, 119, 237, 473, 945, 1889, 90, 181, 100, 199, 108, 217, 435, 871, 1743, 3487, 6975, 13951, 27903, 55807, 162, 323, 645, 1289, 182, 365, 731, 1463, 2927, 210, 419, 228, 457, 232, 463, 242, 485, 971, 262, 523, 272, 545, 1091
Offset: 1
Keywords
Examples
We start with a(1) = S = 1. Since 1 is not a prime, a(2) = 2*1 + 1 = 3. 3 is a prime, so now S = -1 and a(3) = prime(3) - 1 = 5-1 = 4. 4 is not a prime, so a(4) = 2*4 - 1 = 7. And so on.
Links
- N. J. A. Sloane, Table of n, a(n) for n = 1..4000
- Michael De Vlieger, Log log scatterplot of log_10 a(n), n = 1..2^15.
- Michael De Vlieger, Compactified table of n, a(n) = m * 2^k + b, n = 1..10^5, where k is the 2-adic valuation of a(n)-1 if a(n) is odd, or a(n) if a(n) is even, b = a(n) mod 2, and m = (a(n)-b)/2^k.
Programs
-
Maple
# To get the first 100 terms: A:=Array(1..1200, 0); t:=1; A[1]:= t; S:=1; for n from 2 to 100 do if not isprime(t) then t:=2*t+S; else S:=-S; t:=ithprime(n)+S; fi; A[n]:=t; od: [seq(A[n], n=1..100)];
-
Mathematica
nn = 120; s = j = 1; {1}~Join~Reap[Do[If[PrimeQ[j], s = -s; k = Prime[n] + s, k = 2 j + s]; j = k; Sow[k], {n, 2, nn}] ][[-1, 1]] (* Michael De Vlieger, Aug 11 2024 *) m = 120; ToExpression /@ Import["https://oeis.org/A373805/a373805.txt", "Data"][[;; m, -1]] (* Generate up to m = 10^5 terms from compactified a-file, Michael De Vlieger, Aug 13 2024 *)
-
Python
from sympy import sieve, isprime from itertools import count, islice def A373805_gen(): # generator of terms an = S = 1 for n in count(2): yield an if not isprime(an): an = 2*an + S else: S *= -1; an = sieve[n] + S print(list(islice(A373805_gen(), 60))) # Michael S. Branicky, Aug 12 2024
Comments