little elephants and divisors

http://www.codechef.com/viewsolution/2711088
why is it wrong?

Well, you don’t understand problem statement correctly. You should find minimal number x, that x divide all numbers in array A.

If you have only one number in array A, you print number A[0] as result. But what if A[0]=4. Then you claim, that smallest number is x=4. Yes, 4 divide all numbers in array, but number 2 also divide all numbers, but it’s smaller than 4. So correct result is 2.

Your code looks, like you want to find greatest common divisor. You don’t do it quick enough (and you can use C++ function __gcd() in library allgorithm) and it’s not the best approach. Because you’re looking for smallest common divisor.

I hope you now understand your problem. If you need further explanation, just ask.

//