![]() |
VOOZH | about |
Given two numbers N, M in the bases X, Y and another base P. The task is to find the product of N and M and represent the product in base P.
Examples:
Input: N = 101, M = 110, X = 2, Y = 2, P = 16
Output:1E
Explanation: NX * MY = (101)2 * (110)2 = (11110)2
(11110)2 = (1E)16Input: N = 101, M = A, X = 2, Y = 20, P = 16
Output: 32
Explanation: Nx = (101)2 = (5)20
NX * MY = (5)20 * (A)20 = (2A)20
(2A)20 = (32)16
Approach: The approach is to convert the given numbers in decimal, perform the product and then turn it back to a number of base p. Follow the steps mentioned below:
Below is the implementation of the above approach.
1E
Time Complexity: O(D) where D is the maximum number of digits in N, M and product
Auxiliary Space: O(1)