diff --git a/DIRECTORY.md b/DIRECTORY.md index 7d3ceee144be..16ff73467c54 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -548,7 +548,7 @@ * [Basic Maths](maths/basic_maths.py) * [Binary Exp Mod](maths/binary_exp_mod.py) * [Binary Exponentiation](maths/binary_exponentiation.py) - * [Binary Exponentiation 2](maths/binary_exponentiation_2.py) + * [Binary Exponentiation 2](maths/binary_multiplication.py) * [Binary Exponentiation 3](maths/binary_exponentiation_3.py) * [Binomial Coefficient](maths/binomial_coefficient.py) * [Binomial Distribution](maths/binomial_distribution.py) diff --git a/maths/binary_exponentiation_2.py b/maths/binary_multiplication.py similarity index 71% rename from maths/binary_exponentiation_2.py rename to maths/binary_multiplication.py index af8f776dd266..dcac6e383fe0 100644 --- a/maths/binary_exponentiation_2.py +++ b/maths/binary_multiplication.py @@ -12,6 +12,29 @@ def b_expo(a: int, b: int) -> int: + """ + Calculate the result of multiplying 'a' and 'b' using bitwise multiplication. + Parameters: + a (int): The first number. + b (int): The second number. + Returns: + int: The result of 'a' multiplied by 'b'. + Examples: + >>> b_expo(2, 3) + 6 + >>> b_expo(5, 0) + 0 + >>> b_expo(3, 4) + 12 + >>> b_expo(10, 5) + 50 + >>> b_expo(0, 5) + 0 + >>> b_expo(2, 1) + 2 + >>> b_expo(1, 10) + 10 + """ res = 0 while b > 0: if b & 1: @@ -23,6 +46,12 @@ def b_expo(a: int, b: int) -> int: return res +if __name__ == "__main__": + import doctest + + doctest.testmod() + + def b_expo_mod(a: int, b: int, c: int) -> int: res = 0 while b > 0: