diff --git a/src/multiplication.c b/src/multiplication.c index 9512607..5262de3 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -138,6 +138,18 @@ int multiply_using_differences(int num1, int num2) { return (sum - difference) * difference / 4; } +int multiply_recursive_optimized(int num1, int num2) { + if (num2 == 0) { + return 0; + } + int result = multiply_recursive_optimized(num1, num2 >> 1); + result <<= 1; + if (num2 & 1) { + result += num1; + } + return result; +} + diff --git a/src/multiplication.h b/src/multiplication.h index c2b8540..1524c22 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -21,6 +21,7 @@ int multiply_by_prime_and_its_square(int num, int prime); int multiply_by_odd(int num, int factor); int multiply_using_binary_enumeration(int num1, int num2); int multiply_using_differences(int num1, int num2); +int multiply_recursive_optimized(int num1, int num2); #endif // MULTIPLICATION_H