-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext2.py
More file actions
22 lines (22 loc) · 770 Bytes
/
Copy pathtext2.py
File metadata and controls
22 lines (22 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
x=int(input('give me a number x'))
y=int(input('give me a number y'))
def Karatsuba (x,y):
if x<=10 and y<=10:
return (x*y)
else:
b=len(str(x))
c=len(str(y))
d=max(b,c)
xz=x//10**(b-1)
xy=x%10**(b-1)
yz=y//10**(c-1)
yy=y%10**(c-1)
if xy>10 and yy>10:
return (xz*10**(b-1)+Karatsuba(xy,xy))*(yz*10**(c-1)+Karatsuba(yy,yy))
elif xy<10 and yy>10:
return (xz*10**(b-1)+xy)*(yz*10**(c-1)+Karatsuba(yy,yy))
elif xy>10 and yy<10:
return (xz * 10 ** (b - 1) +Karatsuba(xy,xy) ) * (yz * 10 ** (c - 1) + yy)
elif xy<10 and yy<10:
return (xz * 10 ** (b - 1) + xy) * (yz * 10 ** (c - 1) + yy)
print(Karatsuba(x,y))