Add typing to binary_exp_mod.py (#9469)

* Add typing to  binary_exp_mod.py

* Update binary_exp_mod.py

* review changes
This commit is contained in:
Saksham Chawla 2023-10-02 20:00:34 +05:30 committed by GitHub
parent 89a65a8617
commit 97154cfa35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
def bin_exp_mod(a, n, b): def bin_exp_mod(a: int, n: int, b: int) -> int:
""" """
>>> bin_exp_mod(3, 4, 5) >>> bin_exp_mod(3, 4, 5)
1 1
@ -13,7 +13,7 @@ def bin_exp_mod(a, n, b):
if n % 2 == 1: if n % 2 == 1:
return (bin_exp_mod(a, n - 1, b) * a) % b return (bin_exp_mod(a, n - 1, b) * a) % b
r = bin_exp_mod(a, n / 2, b) r = bin_exp_mod(a, n // 2, b)
return (r * r) % b return (r * r) % b