|
@ -230,7 +230,7 @@ int bitwisee_multi(int num1, int num2) { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int karatsuba_multi(int num1, int num2) { |
|
|
|
|
|
|
|
|
int karatsu_multi(int num1, int num2) { |
|
|
// Base case: If numbers are less than 10, return their product directly |
|
|
// Base case: If numbers are less than 10, return their product directly |
|
|
if (num1 < 10 || num2 < 10) { |
|
|
if (num1 < 10 || num2 < 10) { |
|
|
return num1 * num2; |
|
|
return num1 * num2; |
|
@ -246,9 +246,9 @@ int karatsuba_multi(int num1, int num2) { |
|
|
int d = num2 % (int)pow(10, m2); |
|
|
int d = num2 % (int)pow(10, m2); |
|
|
|
|
|
|
|
|
// Calculate intermediate products |
|
|
// Calculate intermediate products |
|
|
int ac = karatsuba_multi(a, c); |
|
|
|
|
|
int bd = karatsuba_multi(b, d); |
|
|
|
|
|
int ad_bc = karatsuba_multi(a + b, c + d) - ac - bd; |
|
|
|
|
|
|
|
|
int ac = karatsu_multi(a, c); |
|
|
|
|
|
int bd = karatsu_multi(b, d); |
|
|
|
|
|
int ad_bc = karatsu_multi(a + b, c + d) - ac - bd; |
|
|
|
|
|
|
|
|
// Calculate the final result |
|
|
// Calculate the final result |
|
|
return ac * (int)pow(10, 2 * m2) + ad_bc * (int)pow(10, m2) + bd; |
|
|
return ac * (int)pow(10, 2 * m2) + ad_bc * (int)pow(10, m2) + bd; |
|
|