Задачі
Добуток
ən asan yolu python la yazmaq dı.
Digər halda yazmaq üçün string lərin hasili kimi yazmaq lazımdır.
in ruby btw fr=gets.toi tr=gets.toi puts fr*tr
a = int(input ()) b = int(input()) print(a*b)
tagizade, thanks for explanation.
a=int(input()) b=int(input()) print(a*b)
What causes runtime error
import sys sys.setrecursionlimit(10**6)
def karatsuba(a, b): if a == 0 or b == 0: return 0
if a < 10 or b < 10:
return a * b
max_digits = max(len(str(a)), len(str(b)))
split_pos = max_digits // 2
a_high, a_low = divmod(a, 10 ** split_pos)
b_high, b_low = divmod(b, 10 ** split_pos)
p1 = karatsuba(a_high, b_high)
p2 = karatsuba(a_low, b_low)
p3 = karatsuba(a_high + a_low, b_high + b_low) - p1 - p2
return p1 * 10 ** (2 * split_pos) + p3 * 10 ** split_pos + p2
try:
a = int(input())
b = int(input())
print(karatsuba(a, b))
except:
print("Invalid input")
// 80 % with not runtime error