Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- using namespace std;
- const int N=2e5+5;
- int n;
- int a[N],b[N],c[N];
- bool check(int x){
- int t=0;
- for(int i=1;i<=n;i++){
- if(i==x) continue;
- c[++t]=a[i];
- }
- int last=1;
- for(int i=1;i<n-1;i++){
- int y=__gcd(c[i],c[i+1]);
- if(y<last) return false;
- last=y;
- }
- return true;
- }
- int main(){
- int t;
- cin>>t;
- while(t--){
- cin>>n;
- for(int i=1;i<=n;i++) cin>>a[i];
- for(int i=1;i<n;i++) b[i]=__gcd(a[i],a[i+1]);
- int x=-1;
- for(int i=1;i<n-1;i++){
- if(b[i]>b[i+1]){
- x=i;
- break;
- }
- }
- if(x==-1)
- cout<<"YES\n";
- else if(check(x)||check(x+1)||check(x+2))
- cout<<"YES\n";
- else
- cout<<"NO\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment