function karatsuba(a, b) {
if (a < 10 && b < 10) {
return a * b;
}
let n = Math.max(countDigits(a), countDigits(b));
if (n % 2 !== 0) n++;
let p = Math.pow(10, n/2);
let A0 = Math.floor(a / p), A1 = a % p;
let B0 = Math.floor(b / p), B1 = b % p;
let X = karatsuba(A0, B0);
let Y = karatsuba(A1, B1);
let Z = karatsuba(A0 + A1, B0 + B1);
return X * Math.pow(10, n) + (Z - X - Y) * p + Y;
}