You are on page 1of 2

import java.io.

*;
import java.util.*;

public class Solution {

static int gcd(int a,int b)


{
int g;
g=a<b?a:b;
while(a%g!=0 && b%g!=0)
g++;
return g;
}

static int gcdar(int p[])


{
int op,op1=1;
for(int i=0;i<p.length-1;i++)
{
for(int j=i+1;j<p.length;j++)
{
op=gcd(p[i],p[j]);
if(op1<op)
op1=op;
}
}
return op1;
}

public static void main(String[] args) {


/* Enter your code here. Read input from STDIN. Print output to STDOUT.
Your class should be named Solution. */
Scanner sc=new Scanner(System.in);
int t,n;
t=sc.nextInt();
while(t>0)
{
n=sc.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
ar[i]=sc.nextInt();
int hcf=1;
for(int i=0;i<n-1;i++)
{

for(int j=i+1;j<n;j++)
{
int sub[]=Arrays.copyOfRange(ar,i,j);
if(gcdar(sub)>hcf)
hcf=gcdar(sub);

}
}
if(hcf>1)
System.out.println("NO");
else
System.out.println("YES");
t--;
}
}
}

You might also like