>>> invert_modulo(2, 5) 3 >>> invert_modulo(8,7) 1
(a: int, n: int)
| 57 | |
| 58 | # This function find the inverses of a i.e., a^(-1) |
| 59 | def invert_modulo(a: int, n: int) -> int: |
| 60 | """ |
| 61 | >>> invert_modulo(2, 5) |
| 62 | 3 |
| 63 | |
| 64 | >>> invert_modulo(8,7) |
| 65 | 1 |
| 66 | |
| 67 | """ |
| 68 | (b, _x) = extended_euclid(a, n) |
| 69 | if b < 0: |
| 70 | b = (b % n + n) % n |
| 71 | return b |
| 72 | |
| 73 | |
| 74 | # Same a above using InvertingModulo |
no test coverage detected