LEDIV WA error on judge n correct on ideone

i am getting correct answer on ideone and my compiler but on judge it gives WA…please help…

#include<stdio.h>
long int a[100000]={0};
int main(void)
{
 long int t,n,i,min,flag,j,res;
 min=100000;
 scanf("%ld",&t);
 while(t--)
 {
  scanf("%ld",&n);
  for(i=0;i<n;i++)
  {
   scanf("%ld",&a[i]);
   if(a[i]<min)
   {
    min=a[i];
   }
  }
  for(i=2;i<=min;i++)
  {
   flag=1;
   for(j=0;j<n;j++)
   {
    if(a[j]%i!=0)
    {
     flag=0;
     break;
    }
   }
   if(flag==1)
   {
    res=i;
    break;
   }
  }
  if(flag==0)
  {
   res=-1;
  }
  printf("%ld\n",res);
 }
 return 0;
}
//