#!/usr/bin/env python3
"""OEIS A281648: a(n) = numerator(Bernoulli(2n)) mod n.

Conjecture (S. Manyama, 2017, checked for n <= 1024): a(n) = n - 1 exactly when n = 6, 10 or n is
a power of 2.   This script lists every n <= LIMIT with a(n) = n - 1 (for n > 1; a(1) = 0 = n - 1
trivially) and shows that n = 3330 is one of them.

Bernoulli numbers are computed exactly, as fractions, by sympy.   usage: verify.py [LIMIT=3400]
"""
import sys
from sympy import bernoulli

LIMIT = int(sys.argv[1]) if len(sys.argv) > 1 else 3400
OEIS = [0, 1, 1, 3, 0, 5, 0, 7, 1, 9, 0, 5, 0, 7, 5, 15, 0, 11, 0, 9, 1, 11, 0, 13, 0, 13, 19, 7, 0, 19, 0]

def a(n): return int(bernoulli(2 * n).p) % n

assert [a(n) for n in range(1, len(OEIS) + 1)] == OEIS, "does not reproduce the OEIS data"
hits = [n for n in range(2, LIMIT + 1) if a(n) == n - 1]
print("n <= %d with a(n) = n - 1:" % LIMIT, hits)
expected = sorted({6, 10} | {2 ** k for k in range(1, 20) if 2 ** k <= LIMIT})
print("predicted by the conjecture:  ", expected)
print("extra:", [n for n in hits if n not in expected], " missing:", [n for n in expected if n not in hits])
