Last active
February 28, 2025 03:45
-
-
Save mydreambei-ai/6d1509b367a1b709a409326862e5341c to your computer and use it in GitHub Desktop.
Revisions
-
mydreambei-ai revised this gist
Feb 28, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,4 +12,4 @@ def invmod(n, p): return p - q if r == n - 1: return q + 1 return ((p-q) * invmod(r, p)) % p -
mydreambei-ai created this gist
Feb 25, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ def invmod(n, p): if n >=p : q, r = divmod(n, p) if r == 0: raise ValueError("xxx") else: n = r if n == 1: return 1 q, r = divmod(p, n) if r == 1: return p - q if r == n - 1: return q + 1 return ((p-q) * inv(r, p)) % p