Skip to content

Commit fb9e462

Browse files
committed
Add doctests to fermat_little_theorem
Contributes to #9943
1 parent a71618f commit fb9e462

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

maths/fermat_little_theorem.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
66

77

88
def binary_exponentiation(a: int, n: float, mod: int) -> int:
9+
"""
10+
Compute (a^n) % mod using binary exponentiation.
11+
12+
Args:
13+
a: Base number
14+
n: Exponent
15+
mod: Modulus
16+
17+
Returns:
18+
Result of (a^n) % mod
19+
20+
>>> binary_exponentiation(2, 10, 1000)
21+
24
22+
>>> binary_exponentiation(5, 3, 13)
23+
8
24+
>>> binary_exponentiation(10, 0, 7)
25+
1
26+
>>> binary_exponentiation(3, 4, 5)
27+
1
28+
"""
929
if n == 0:
1030
return 1
1131

0 commit comments

Comments
 (0)