RD19 getting WA even the answer shwoing correct

#include
#include

using namespace std;
int GCD(vector& gcd,int small)
{
if(gcd.size()>1)
return 0;
else
{
if(gcd[0]==1)
return 0;
else
return -1;
}
}
int main()
{
int T;
cin>>T;
while(T–)
{
unsigned int N;
int num,i;
cin>>N;
vector A;
A.reserve(N);
for(i=0;i<N;i++)
{
cin>>num;
A.push_back(num);
// cout<<"\t";
}
int smallest=A[0];
for(i=1;i<A.size();i++)
{
if(smallest>A[i])
smallest=A[i];
}

    for(i=0;i<A.size();i++)
    {
        if(((A[i]%smallest==0)&&(A[i]!=smallest))||A[i]==0)
            A.erase(A.begin()+i);
    }
    cout<<GCD(A,smallest)<<endl;
}

return 0;

}

Its shwoing WA where as the answer is correct as i ahve checked in ideone also, can plz anyone point out wheres the problem is?

The answer is ‘0’ if GCD of the sequence if 1 otherwise there is no possible way to make it 1 by deleting any element… so answer is -1

because deleting element will increase the GCD and it will never decrease it…
your logic is probably wrong…
do ,

#include <bits/stdc++.h>  
int gc=A[0];    
for(i=1;i<n;i++){       
   gc = __gcd(gcd,A[i]);       
}    
  
if(gc==1)  
    cout << 0 <<  endl;  
else   
    cout << -1 << endl;

here underscore underscore gcd ( __gcd(a,b) )
is inbuilt function in c++ for finding gcd