# Python program for OEIS A320441
# Michael S. Branicky, Mar 24 2022

# A320434 Number of length-n quasiperiodic binary strings.
data = [0, 2, 2, 4, 4, 10, 10, 26, 22, 56, 68, 118, 126, 284, 274, 542, 604, 1144, 1196, 2284, 2340, 4600, 4876, 9010, 9280, 18286, 18476, 35546, 36886, 70320, 72092, 140578, 141736, 276812, 282694]

# (Python)
from numba import njit
@njit
def ok2(w): # after PARI by Remy Sigrist in A320441
    tt = 0
    l = 0
    while True:
        l += 1
        twol = 2**l
        t = w%twol
        if t != tt:
            if t == w:
                return 0
            r, g = w, l
            g -= 1
            while g >= 0 and r >= t:
                r //= 2
                if r%twol == t:
                    if r == t:
                       return 1
                    else:
                       g=l
                g -= 1
            tt = t
@njit
def a(n):
    c = 0
    for i in range(2**(n-1), 2**n):
        if ok2(i):
            c += 1
    return 2*c
print([a(n) for n in range(1, 16)]) # ~~~~

print(data)
print()

from time import time
time0 = time()

alst = []
for n in range(1, 37):
    an = a(n)
    alst.append(an)
    print(n, an, len(str(alst))-2, time()-time0, flush=True)
    print("   ", alst, flush=True)
    print("   ", data, flush=True)