Examples: >>> power(2, 15, 3) 2 >>> power(5, 1, 30) 5
(x: int, y: int, mod: int)
| 15 | |
| 16 | |
| 17 | def power(x: int, y: int, mod: int) -> int: |
| 18 | """ |
| 19 | Examples: |
| 20 | >>> power(2, 15, 3) |
| 21 | 2 |
| 22 | >>> power(5, 1, 30) |
| 23 | 5 |
| 24 | """ |
| 25 | |
| 26 | if y == 0: |
| 27 | return 1 |
| 28 | temp = power(x, y // 2, mod) % mod |
| 29 | temp = (temp * temp) % mod |
| 30 | if y % 2 == 1: |
| 31 | temp = (temp * x) % mod |
| 32 | return temp |
| 33 | |
| 34 | |
| 35 | def is_carmichael_number(n: int) -> bool: |
no outgoing calls
no test coverage detected