We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 954398b commit de622b9Copy full SHA for de622b9
multiplication/karatsuba.py
@@ -0,0 +1,16 @@
1
+def karatsuba(x,y):
2
+ if len(str(x)) or len(str(y)) :
3
+ return x*y
4
+ else:
5
+ n = max(len(str(x)),len(str(y)))
6
+ z = n / 2
7
+ a = x / 10**(z)
8
+ b = x % 10**(z)
9
+ c = y / 10**(z)
10
+ d = y % 10**(z)
11
+ ac = karatsuba(a,c)
12
+ bd = karatsuba(b,d)
13
+ adbc = karatsuba(a+b,c+d) - ac - bd
14
+ return ac * 10**(2*z) + (adbc * 10**z) + bd
15
+
16
+karatsuba (923,1723)
0 commit comments