From fb9e4627d3b913b304ae025838dcf64a87e8aa37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Cancio?= Date: Fri, 3 Oct 2025 18:58:20 +0200 Subject: [PATCH] Add doctests to fermat_little_theorem Contributes to #9943 --- maths/fermat_little_theorem.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/maths/fermat_little_theorem.py b/maths/fermat_little_theorem.py index 4a3ecd05ce91..beefe8e82b74 100644 --- a/maths/fermat_little_theorem.py +++ b/maths/fermat_little_theorem.py @@ -6,6 +6,26 @@ def binary_exponentiation(a: int, n: float, mod: int) -> int: + """ + Compute (a^n) % mod using binary exponentiation. + + Args: + a: Base number + n: Exponent + mod: Modulus + + Returns: + Result of (a^n) % mod + + >>> binary_exponentiation(2, 10, 1000) + 24 + >>> binary_exponentiation(5, 3, 13) + 8 + >>> binary_exponentiation(10, 0, 7) + 1 + >>> binary_exponentiation(3, 4, 5) + 1 + """ if n == 0: return 1