Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def divide_and_conquer(x,y):
- if len(str(x)) == 1 or len(str(y)) == 1:
- return x*y
- else:
- n = int(max(len(str(x)), len(str(y))))
- nby2 = int(n / 2)
- a = x // 10**(nby2)
- b = x % 10**(nby2)
- c = y // 10**(nby2)
- d = y % 10**(nby2)
- ac = divide_and_conquer(a,c)
- bd = divide_and_conquer(b,d)
- ad_plus_bc = divide_and_conquer(a+b, c+d) - ac - bd
- prod = ac * 10**(2*nby2) + (ad_plus_bc * 10**nby2) + bd
- return prod
- x = int(input("Enter 20 digit num: "))
- ans = divide_and_conquer(x, x)
- print(f"Square of number {x} is {ans}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement