MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / power

Function power

maths/special_numbers/carmichael_number.py:17–32  ·  view source on GitHub ↗

Examples: >>> power(2, 15, 3) 2 >>> power(5, 1, 30) 5

(x: int, y: int, mod: int)

Source from the content-addressed store, hash-verified

15
16
17def 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
35def is_carmichael_number(n: int) -> bool:

Callers 1

is_carmichael_numberFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected