from sympy import jacobi_symbol as J, factorint, isprime, primepi, primefactors

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

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 a061395(n): return 0 if n==1 else primepi(primefactors(n)[-1])

def a278223(n): return a046523(2*n - 1)

def a049084(n): return primepi(n) if isprime(n) else 0

def a112046(n):
    i=1
    while True:
        if J(i, 2*n + 1)!=1: return i
        else: i+=1

def a112049(n): return a049084(a112046(n))

def a286465(n): return 1 if n==1 else T(a112049(n - 1), a278223(n))

def a(n): return T(a061395(n), a286465(n))