>>> chinese_remainder_theorem2(5,1,7,3) 31 >>> chinese_remainder_theorem2(6,1,4,3) 14
(n1: int, r1: int, n2: int, r2: int)
| 73 | |
| 74 | # Same a above using InvertingModulo |
| 75 | def chinese_remainder_theorem2(n1: int, r1: int, n2: int, r2: int) -> int: |
| 76 | """ |
| 77 | >>> chinese_remainder_theorem2(5,1,7,3) |
| 78 | 31 |
| 79 | |
| 80 | >>> chinese_remainder_theorem2(6,1,4,3) |
| 81 | 14 |
| 82 | |
| 83 | """ |
| 84 | x, y = invert_modulo(n1, n2), invert_modulo(n2, n1) |
| 85 | m = n1 * n2 |
| 86 | n = r2 * x * n1 + r1 * y * n2 |
| 87 | return (n % m + m) % m |
| 88 | |
| 89 | |
| 90 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected