Objects/Documentation
primitives.py
PrimitiveCounter applies the truncated convolution logarithm and Möbius inversion to quotient classes. The tests include the scalar count at one million.
Download ↓"""Exact formal convolution logarithm on integer magnitude x finite unit quotient.
No list of integer primes is used by this oracle. Rational arithmetic only.
"""
from fractions import Fraction
from functools import lru_cache
from bisect import bisect_right
from math import gcd
@lru_cache(None)
def mobius(k):
if k==1:return 1
return -sum(mobius(d) for d in range(1,k) if k%d==0)
def iroot(x,k):
lo=0;hi=1<<( (x.bit_length()+k-1)//k )
while lo<hi: