utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:python-assignments 作者: stanfordpython 项目源码 文件源码
def modinv(a, b):
    """Returns the modular inverse of a mod b.

    Pre: a < b and gcd(a, b) = 1

    Adapted from https://en.wikibooks.org/wiki/Algorithm_Implementation/
    Mathematics/Extended_Euclidean_algorithm#Python
    """
    saved = b
    x, y, u, v = 0, 1, 1, 0
    while a:
        q, r = b // a, b % a
        m, n = x - u*q, y - v*q
        b, a, x, y, u, v = a, r, u, v, m, n
    return x % saved
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号