#include #include #include using namespace std; struct BigInt { enum {MAXN = 10005}; //-----------初始化 bool p;//p=0表正数,p=1表负数 int len, s[MAXN]; BigInt() { memset(s, 0, sizeof(s)); len = 1; p = 0; } //-----------转字符串,便于输出 string str() const { string res = ""; for (int i = 1; i <= len; i++) res = (char)(s[i] + '0') + res; if (res == "") res = "0"; if (p) res = "-" + res; return res; } //-----------赋值 BigInt operator=(const string &n) { memset(s, 0, sizeof(s)); len = n.length(); p = 0; for (int i = 1; i <= len - 1; i++) s[i] = n[len - i] - '0'; if (n[0] == '-') p = 1; else s[len] = n[0] - '0'; while (!s[len] && len > 1) len--; if (len == 1 && s[1] == 0) p = 0; return *this; } BigInt operator=(const int &n) { memset(s, 0, sizeof(s)); int k = n; len = 0; if (k < 0) { k = -k; p = 1; } else p = 0; while (k) { len++; s[len] = k % 10; k /= 10; } if (!len) len++; return *this; } BigInt operator=(const BigInt &a) { //memset(s,0,sizeof(s)); len = a.len; p = a.p; memcpy(s, a.s, sizeof(s)); //for (int i=1;i<=len;i++) // s[i]=a.s[i]; return *this; } BigInt(const string n) { *this = n; } BigInt(const int n) { *this = n; } //-----------比较(大小、等于和不等于) bool operator<(const BigInt &a) const { if (a.p && !p) return 0; if (!a.p && p) return 1; if (len != a.len) if (!p) return len < a.len; else return len > a.len; for (int i = len; i >= 1; i--) if (s[i] != a.s[i]) if (!p) return s[i] < a.s[i]; else return s[i] > a.s[i]; return 0; } bool operator>(const BigInt &a) const { return a < *this; } bool operator<=(const BigInt &a) const { return !(a < *this); } bool operator>=(const BigInt &a) const { return !(*this < a); } bool operator!=(const BigInt &a) const { return *this < a || *this > a; } bool operator==(const BigInt &a) const { return !(*this != a); } //-----------取负值,便于四则运算 BigInt operator-() const { BigInt a(*this); if (a != 0) a.p = !a.p; return a; } //-----------两数相加 BigInt operator+(const BigInt &a) const { BigInt c; if (!a.p && !p) c.p = 0; else if (a.p && p) c.p = 1; else if (p) return a - (-*this); else return *this - (-a); c.len = max(len, a.len) + 1; for (int i = 1, g = 0; i <= c.len; i++) { int x = s[i] + a.s[i] + g; c.s[i] = x % 10; g = x / 10; } while (!c.s[c.len] && c.len > 1) c.len--; if (!c.s[1] && c.len == 1) c.p = 0; return c; } BigInt operator+=(const BigInt &a) { *this = *this + a; return *this; } //-----------两数相减 BigInt operator-(const BigInt &d) const { BigInt a(*this), b(d), c, tmp; if (!a.p && !b.p) { if (a < b) { tmp = a; a = b; b = tmp; c.p = 1; } } else if (a.p && b.p) { if (a < b) c.p = 1; else { tmp = a; a = b; b = tmp; c.p = 0; } a = -a; b = -b; } else if (!a.p) return a + (-b); else return -(-a + b); c.len = max(a.len, b.len); for (int i = c.len; i >= 1; i--) { c.s[i] = a.s[i] - b.s[i]; int k = i; while (c.s[k] < 0) { c.s[k] += 10; c.s[k + 1]--; k++; } } while (!c.s[c.len] && c.len > 1) c.len--; if (!c.s[1] && c.len == 1) c.p = 0; return c; } BigInt operator-=(const BigInt &a) { *this = *this - a; return *this; } //-----------两数相乘 BigInt operator*(const BigInt &a) const { BigInt c; c.p = p ^ a.p; c.len = len + a.len; for (int i = 1; i <= len; i++) for (int j = 1; j <= a.len; j++) c.s[i + j - 1] += s[i] * a.s[j]; for (int i = 1; i <= c.len; i++) { c.s[i + 1] += c.s[i] / 10; c.s[i] %= 10; } while (!c.s[c.len] && c.len > 1) c.len--; if (!c.s[1] && c.len == 1) c.p = 0; return c; } BigInt operator*=(const BigInt &a) { *this = (*this) * a; return *this; } //-----------两数相除 //高精度除以低精度 BigInt operator/(const int &b) const { BigInt c; int a = b; if (a < 0) a = -a; if (*this == 0 || a == 0) return BigInt(0); //若除数或被除数为0,则返回0 long long k = 0; for (int i = len; i >= 1; i--) { k = k * 10 + s[i]; c.s[i] = k / a; k %= a; } c.p = p ^ (b > 0 ? 0 : 1); c.len = len; while (!c.s[c.len] && c.len > 1) c.len--; if (!c.s[1] && c.len == 1) c.p = 0; return c; } //高精度除以高精度 BigInt operator/(const BigInt &b) const { BigInt tmp, a(b), c; if (a.p) a.p = 0; if (*this == 0 || a == 0) return BigInt(0); //若除数或被除数为0,则返回0 for (int i = len; i >= 1; i--) { if (!tmp.s[1] && tmp.len == 1) tmp.len--; tmp.len++; for (int j = tmp.len; j > 1; j--) tmp.s[j] = tmp.s[j - 1]; tmp.s[1] = s[i]; while (tmp >= a) { tmp -= a; c.s[i]++; } } c.p = p ^ b.p; c.len = len; while (!c.s[c.len] && c.len > 1) c.len--; if (!c.s[1] && c.len == 1) c.p = 0; return c; } BigInt operator/=(const int &a) { *this = *this / a; return *this; } BigInt operator/=(const BigInt &a) { *this = *this / a; return *this; } //-----------两数取模 //低精度模高精度 BigInt operator%(const int &b) const { BigInt c; int a = b; if (a < 0) a = -a; if (a == 0) return *this; if (*this == 0) return BigInt(0); long long k = 0; for (int i = len; i >= 1; i--) { k = k * 10 + s[i]; k %= a; } c = k; c.p = p; while (!c.s[c.len] && c.len > 1) c.len--; if (!c.s[1] && c.len == 1) c.p = 0; return c; } //高精度模高精度 BigInt operator%(const BigInt &b) const { BigInt c, a(b); if (a.p) a.p = 0; if (a == 0) return *this; if (*this == 0) return BigInt(0); for (int i = len; i >= 1; i--) { if (!c.s[1] && c.len == 1) c.len--; c.len++; for (int j = c.len; j > 1; j--) c.s[j] = c.s[j - 1]; c.s[1] = s[i]; while (c >= a) c -= a; } c.p = p; while (!c.s[c.len] && c.len > 1) c.len--; if (!c.s[1] && c.len == 1) c.p = 0; return c; } BigInt operator%=(const int &a) { *this = *this % a; return *this; } BigInt operator%=(const BigInt &a) { *this = *this % a; return *this; } //-----------流输入输出 friend istream& operator>>(istream &in, BigInt &x) { string s; in >> s; x = s; return in; } friend ostream& operator<<(ostream &out, const BigInt &x) { out << x.str(); return out; } }; const int MAXN = 105; BigInt a[MAXN]; int main() { int T; cin >> T; while (T--) { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; bool flag = true; for (int i = 1; i < n; i++) { if (a[i] == BigInt(0) && a[i-1] != BigInt(0) || a[i] != BigInt(0) && a[i-1] == BigInt(0)) flag = false; } if (!flag) { cout << "No\n"; continue; } flag = true; for (int i = 1; i < n - 1; i++) { if (a[i-1]*a[i+1] != a[i]*a[i]) { flag = false; break; } } if (flag) cout << "Yes\n"; else cout << "No\n"; } return 0; }