GCD operations CodeChef lunchtime Problem solution with explanation-
if it is possible to obtain or
"NO"if it is impossible.
2 3 1 2 2 4 1 2 3 2
GCD operations codechef lunchtime Problem solution-
This is not a thought question actually. You need to know a few things only-
- GCD of two numbers (a,b) cannot grater then these two numbers.
As mentioned in the question we have to check whether array A can be converted into array B or not.
We can perform any number of operations (gcd).
array A has initially 1-N value.
SO my approach says that I will iterate over the array A and compare value to array B.
if it is matching that will be fine otherwise I will check whether A[i ] is multiple of B[i] or not because we can change A[i] to B[i] only if A[i] is multiple of B[i] as I mentioned above in the first point.
SO this is how we can solve this problem.
code is mention below-