#include<bits/stdc++.h> using namespace std; typedef long long ll; #define endl "\n" inline int gcd(int a, int b) { return b > 0 ? gcd(b, a % b) : a; } inline int lcm(int a, int b) { return a / gcd(a, b) * b; } const int N = 1e5 + 5; int a[N],b[N]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int T = 1; cin >> T; while (T--) { int n, jud = 0; cin >> n; for (int i = 1; i <= n; i++)cin >> a[i]; a[0] = a[n + 1] = 1; for (int i = 1; i <= n + 1; i++) { b[i] = lcm(a[i], a[i-1]); } for (int i = 1; i <= n; i++) { if (a[i] != gcd(b[i], b[i + 1]))jud = 1; } if (jud)cout << "NO" << endl; else cout << "YES" << endl; } }
标签:gcd,int,cin,long,Codeforces,825,Div,Round From: https://www.cnblogs.com/zhujio/p/17365217.html