Consider we have the initial values of two positive integers X and Y. Find the final value of X and Y, such that there will be some alteration as mentioned below −
The number X and Y will be in range [0 and 1018] So we can use the Brute Force approach.
#include<iostream> using namespace std; void alterNumber(long long x, long long y) { while (1) { if (x == 0 || y == 0) break; if (x >= 2 * y) x = x % (2 * y); else if (y >= 2 * x) y = y % (2 * x); else break; } cout << "X: " << x << "\n" << "Y: " << y; } int main() { long long x = 12, y = 5; alterNumber(x, y); }
X: 0 Y: 1