This function find the inverses of a i.e., a^(-1) >>> invert_modulo(2, 5) 3 >>> invert_modulo(8,7) 1
(a: int, n: int)
| 41 | |
| 42 | |
| 43 | def invert_modulo(a: int, n: int) -> int: |
| 44 | """ |
| 45 | This function find the inverses of a i.e., a^(-1) |
| 46 | |
| 47 | >>> invert_modulo(2, 5) |
| 48 | 3 |
| 49 | |
| 50 | >>> invert_modulo(8,7) |
| 51 | 1 |
| 52 | |
| 53 | """ |
| 54 | (b, _x) = extended_euclid(a, n) # Implemented below |
| 55 | if b < 0: |
| 56 | b = (b % n + n) % n |
| 57 | return b |
| 58 | |
| 59 | |
| 60 | # ------------------ Finding Modular division using invert_modulo ------------------- |
no test coverage detected