from sympy import prime, factorint, divisors, divisor_count, mobius
import math

def A(n): return n - 2**int(math.floor(math.log(n, 2)))

def b(n): return n + 1 if n<2 else prime(1 + (len(bin(n)[2:]) - bin(n)[2:].count("1"))) * b(A(n))

def a005940(n): return b(n - 1)

def a051064(n): return -sum([mobius(3*d)*divisor_count(n/d) for d in divisors(n)])

def P(n):
    f = factorint(n)
    return sorted([f[i] for i in f])

def a046523(n):
    x=1
    while True:
        if P(n) == P(x): return x
        else: x+=1

def T(n, m): return ((n + m)**2 - n - 3*m + 2)/2

def a278222(n): return a046523(a005940(n + 1))

def a(n): return T(a051064(n), a278222(n))