#K79937. Multiply Large Numbers Represented as Strings

    ID: 35419 Type: Default 1000ms 256MiB

Multiply Large Numbers Represented as Strings

Multiply Large Numbers Represented as Strings

You are given two non-negative integers represented as strings. Your task is to compute and output the product of these numbers also as a string. The numbers may be very large, so you cannot convert them directly to integers. Instead, you must simulate the multiplication process that is used in elementary arithmetic.

The multiplication should be performed digit by digit as follows:

  • If any of the input numbers is "0", the result is "0".
  • Otherwise, multiply each digit of the first number by each digit of the second number and add the results accordingly, carrying over digits as needed.

The expected solution should read the two strings from standard input (stdin) and output the product to standard output (stdout).

Note: Make sure the final result does not contain any leading zeros.

inputFormat

The input consists of two lines. The first line contains the first non-negative integer as a string, and the second line contains the second non-negative integer as a string.

Example:

123
456

outputFormat

Output a single line containing the product of the two numbers as a string.

Example:

56088
## sample
123
456
56088