Problem link
Suppose the given list of divisors is a list of almost all divisors of some x (in other words, suppose that the answer exists). Then the minimum divisor multiplied by maximum divisor should be x. This is true because if we have a divisor i we also have a divisor ni. Let's sort all divisors and let x=d1⋅dn.
Now we need to check if all divisors of x except 1 and x are the permutation of the array d (check that our answer is really correct). We can find all divisors of x in O(x−−√), sort them and compare with the array d. If arrays are equal then the answer is x otherwise the answer is -1.
A solution in c++
0 Comments
If you have any doubts, Please let me know