We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I have found an easier solution to this problem.Here is the algo.
While reading the numbers keep track of the the least two distinct nos.
Find the least common divisor of these nos.(>1)
If it is 1,then condition is possible.
Otherwise
check if the lowest common divisor divides all the numbers.
If so the subset is not possible.
But if it leaves a remainder for at least one no. then the subset is possible.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and GCD
You are viewing a single comment's thread. Return to all comments →
I have found an easier solution to this problem.Here is the algo. While reading the numbers keep track of the the least two distinct nos. Find the least common divisor of these nos.(>1) If it is 1,then condition is possible. Otherwise check if the lowest common divisor divides all the numbers. If so the subset is not possible. But if it leaves a remainder for at least one no. then the subset is possible.