U

9. Generate Multiplication Table

Easy

Problem Description

Given two integers NN and KK (K≥1K \ge 1), print the multiplication table of NN from 11 up to KK.

Input Format

A single line containing two space-separated integers NN and KK.

Output Format

Print KK lines. The ii-th line (1≤i≤K1 \le i \le K) should be formatted exactly as: N x i = result

Example 1:
Input:
5 4
Output:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
Explanation: Multiplication table of 5 up to multiplier 4.
Example 2:
Input:
3 1
Output:
3 x 1 = 3
Explanation: Multiplier K = 1, so only 3 x 1 is printed.
Example 3:
Input:
-2 3
Output:
-2 x 1 = -2
-2 x 2 = -4
-2 x 3 = -6
Explanation: Multiplication table with negative multiplicand N = -2.
Constraints:
  • -10^5 <= N <= 10^5
  • 1 <= K <= 1000
  • Time complexity target: O(K)
  • Auxiliary space target: O(1)
Follow up:How would you print a 2D N x N multiplication grid aligned with fixed-width column padding?
1,180 Online