Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Given integers X, Y, and Okay, the duty is to make X and Y equal in no more than Okay operations by making use of the next operations:
Examples:
Enter: X = 10, Y = 20, Okay = 4
Output: YES
Rationalization: One optimum resolution to make them equal is:
First select A = 2 and do X = X/2 so now X is the same as 5.
Now select A = 4 and do Y = Y/4 so now Y is the same as 5.
Since we’ve got utilized solely two operations right here which is lower than Okay
to make X and Y equal and in addition higher than one.
Due to this fact the reply is YES.Enter: X = 2, Y = 27, Okay = 1
Output: NO
Rationalization: There isn’t any potential strategy to make X and Y equal
in lower than or equal to 1 Operation.
Method: To resolve the issue observe the under thought:
Listed below are solely two circumstances potential:
 When Okay is the same as one and
 When Okay is larger than 1
If Okay is the same as one then it’s potential to make X and Y equal solely when both X is divisible by Y or Y is divisible by X
If Okay is larger than 1 then X and Y will be equal and higher than 1 solely when their GCD is larger than 1.
Observe the steps talked about under to implement the thought:
Under is the implementation for the above method:

Time Complexity: O(1)
Auxiliary House: O(1)