Skip to content

Instantly share code, notes, and snippets.

View wzjoriv's full-sized avatar
🌴

Josue wzjoriv

🌴
View GitHub Profile
@cmpute
cmpute / lgcd.py
Created June 11, 2022 05:30
Python implementation of (extended) Lehmer's GCD algorithm
import math, random
def lgcd(x, y):
if x < y:
return lgcd(y, x)
shift = max(x.bit_length() // 64, y.bit_length() // 64)
xbar = x >> (shift * 64)
ybar = y >> (shift * 64)
while y > 2**64: