Submit solution(1100)

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll x1,x2,a[1000],n;
int main(){
    ll t;
    scanf("%lld",&t);
    while(t--){
        bool flag1,flag2;
        flag1=flag2=0;
        x1=x2=0;
        scanf("%lld",&n);
        for(int i=1;i<=n;i++){
            cin>>a[i];
            if(i%2)    x1=__gcd(x1,a[i]);
            else x2=__gcd(x2,a[i]);
        }
        for(int i=1;i<=n;i++){
            if(i%2){
                if(a[i]%x2==0)flag1=1;            
            }
            else {
                if(a[i]%x1==0)flag2=1;                 
            }
        }
        if(flag1==0) printf("%lld\n",x2);
        else if(flag2==0) printf("%lld\n",x1);
        else printf("0\n"); 
    }
}

 

上一篇:Codeforces Round #768 (Div. 2) C. And Matching


下一篇:前缀和(原理+应用)