Skip to content

Commit 9ff4b5d

Browse files
Add doctests to binary_exponentiation in fermat_little_theorem
1 parent e3b01ec commit 9ff4b5d

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

maths/fermat_little_theorem.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44
# Here we assume that p is a prime number, b divides a, and p doesn't divide b
55
# Wikipedia reference: https://en.wikipedia.org/wiki/Fermat%27s_little_theorem
66

7-
87
def binary_exponentiation(a: int, n: float, mod: int) -> int:
8+
"""
9+
Compute (a^n) % mod using binary exponentiation.
10+
11+
>>> binary_exponentiation(2, 5, 13)
12+
6
13+
>>> binary_exponentiation(3, 4, 5)
14+
1
15+
>>> binary_exponentiation(10, 0, 7)
16+
1
17+
"""
918
if n == 0:
1019
return 1
1120

0 commit comments

Comments
 (0)