From fc3702b925e4ad1b6f6c42b0e7f6d6d97668c88b Mon Sep 17 00:00:00 2001 From: Chetan Sanjay Shivade Date: Mon, 2 Oct 2023 22:25:51 +0530 Subject: [PATCH 1/2] Renamed maths/binary_exponentiation_2.py to binary_multiplication.py --- ...ntiation_2.py => binary_multiplication.py} | 21 ++++++++++++++++++- scripts/validate_filenames.py | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) rename maths/{binary_exponentiation_2.py => binary_multiplication.py} (82%) diff --git a/maths/binary_exponentiation_2.py b/maths/binary_multiplication.py similarity index 82% rename from maths/binary_exponentiation_2.py rename to maths/binary_multiplication.py index af8f776dd266..90630a66ef3b 100644 --- a/maths/binary_exponentiation_2.py +++ b/maths/binary_multiplication.py @@ -1,5 +1,5 @@ """ -* Binary Exponentiation with Multiplication +* Binary Multiplication * This is a method to find a*b in a time complexity of O(log b) * This is one of the most commonly used methods of finding result of multiplication. * Also useful in cases where solution to (a*b)%c is required, @@ -12,6 +12,15 @@ def b_expo(a: int, b: int) -> int: + """ + Find Binary Multiplication + + >>> b_expo(2,3) + 6 + + >>> b_expo(-2,3) + -6 + """ res = 0 while b > 0: if b & 1: @@ -24,6 +33,16 @@ def b_expo(a: int, b: int) -> int: def b_expo_mod(a: int, b: int, c: int) -> int: + """ + Find Binary Exponiation Mode + Given method work like (a*b)%c + + + >>> b_expo_mod(2,3,4) + 2 + >>> b_expo_mod(2,3,3) + 0 + """ res = 0 while b > 0: if b & 1: diff --git a/scripts/validate_filenames.py b/scripts/validate_filenames.py index ed23f3907114..b52f4f52fc2d 100755 --- a/scripts/validate_filenames.py +++ b/scripts/validate_filenames.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python import os try: From 75e807af0edbc67d693bade229621de53b294b1b Mon Sep 17 00:00:00 2001 From: Chetan Sanjay Shivade Date: Mon, 2 Oct 2023 22:37:35 +0530 Subject: [PATCH 2/2] Renamed maths/binary_exponentiation_2.py to binary_multiplication.py --- maths/binary_multiplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/binary_multiplication.py b/maths/binary_multiplication.py index 90630a66ef3b..e1ef9c16f62d 100644 --- a/maths/binary_multiplication.py +++ b/maths/binary_multiplication.py @@ -1,5 +1,5 @@ """ -* Binary Multiplication +* Binary Exponentiation with Multiplication * This is a method to find a*b in a time complexity of O(log b) * This is one of the most commonly used methods of finding result of multiplication. * Also useful in cases where solution to (a*b)%c is required,