|
U
Pro9. Generate Multiplication Table
Easy
Problem Description
Given two integers N and K (K≥1), print the multiplication table of N from 1 up to K.
Input Format
A single line containing two space-separated integers N and K.
Output Format
Print K lines. The i-th line (1≤i≤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^51 <= K <= 1000Time 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
Code
|Loading Code Editor...
SavedLn 1, Col 1
input =
Sandboxed Engine
Ctrl+Enter = Run | Ctrl+Shift+Enter = Submit