Skip to content

Instantly share code, notes, and snippets.

@pjt33
pjt33 / MO404760.py
Last active October 4, 2021 12:37
Interpolating integer polynomials with small coefficients
#!/usr/bin/pypy3
from heapq import heappush, heappop
def mod_inv(a: int, m: int) -> int:
lastremainder, remainder = a % m, m
x, lastx, y, lasty = 0, 1, 1, 0
while remainder:
lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder)
x, lastx = lastx - quotient*x, x