import java.io.*;
class GFG {
static long a, b;
static int[] linearConvolution;
static int length;
static int countDigits(long num)
{
int count = 0;
while (num > 0) {
num /= 10;
count++;
}
return count;
}
static void schonhageStrassenMultiplication()
{
findLinearConvolution();
performCarry();
}
static void findLinearConvolution()
{
int aDigits = countDigits(a);
int bDigits = countDigits(b);
long temp = a;
length = aDigits + bDigits - 1;
linearConvolution = new int[length];
for (int i = 0; i < aDigits; i++, b /= 10) {
a = temp;
for (int j = 0; j < bDigits; j++, a /= 10) {
linearConvolution[i + j]
+= (b % 10) * (a % 10);
}
}
System.out.print("The Linear Convolution is: [ ");
for (int i = length - 1; i >= 0; i--) {
System.out.print(linearConvolution[i] + " ");
}
System.out.println("]");
}
static void performCarry()
{
long product = 0;
int carry = 0, base = 1;
for (int i = 0; i < length; i++) {
linearConvolution[i] += carry;
product
= product
+ (base * (linearConvolution[i] % 10));
carry = linearConvolution[i] / 10;
base *= 10;
}
System.out.println("\nThe Product is : " + product);
}
public static void main(String[] args)
{
a = 2604;
b = 1812;
schonhageStrassenMultiplication();
}
}