![]() |
VOOZH | about |
Given three positive integers X, Y, and Z. The task is to find two numbers A and B of X and Y digits respectively with their GCD having Z digits. where Z ≤ min(X, Y). If there are multiple possible answers print any of them.
Examples:
Input: X = 2, Y = 3, Z = 1
Output: A = 11, B = 100
Explanation: A and B contains 2 and 3 digits respectively and GCD(A, B) is 1 which has 1 digit.Input: X = 2, Y = 2, Z = 2
Output: A = 13, B = 26
Approach: The task can be solved using some observations. Calculate A equals 10x-1, B as 10y-1, and C as 10z-1. Increment A with C to achieve GCD with Z digits. Follow the below steps to solve the problem:
Below is the implementation of the above approach:
A = 11 B = 100
Time Complexity: O(max(X, Y))
Auxiliary Space: O(1)