結果

問題 No.2074 Product is Square ?
ユーザー tanakanotarou2tanakanotarou2
提出日時 2022-09-16 23:49:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 7,802 bytes
コンパイル時間 2,834 ms
コンパイル使用メモリ 221,060 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-21 23:31:02
合計ジャッジ時間 7,678 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 4 ms
5,248 KB
testcase_02 AC 5 ms
5,248 KB
testcase_03 AC 4 ms
5,248 KB
testcase_04 AC 5 ms
5,248 KB
testcase_05 AC 5 ms
5,248 KB
testcase_06 AC 5 ms
5,248 KB
testcase_07 AC 5 ms
5,248 KB
testcase_08 AC 5 ms
5,248 KB
testcase_09 AC 4 ms
5,248 KB
testcase_10 AC 4 ms
5,248 KB
testcase_11 AC 69 ms
5,248 KB
testcase_12 AC 147 ms
5,248 KB
testcase_13 AC 465 ms
5,248 KB
testcase_14 AC 155 ms
5,248 KB
testcase_15 AC 71 ms
5,248 KB
testcase_16 AC 148 ms
5,248 KB
testcase_17 AC 460 ms
5,248 KB
testcase_18 AC 153 ms
5,248 KB
testcase_19 AC 75 ms
5,248 KB
testcase_20 AC 166 ms
5,248 KB
testcase_21 AC 462 ms
5,248 KB
testcase_22 AC 148 ms
5,248 KB
testcase_23 AC 69 ms
5,248 KB
testcase_24 AC 150 ms
5,248 KB
testcase_25 AC 457 ms
5,248 KB
testcase_26 AC 144 ms
5,248 KB
testcase_27 AC 66 ms
5,248 KB
testcase_28 AC 148 ms
5,248 KB
testcase_29 AC 460 ms
5,248 KB
testcase_30 AC 147 ms
5,248 KB
testcase_31 AC 2 ms
5,248 KB
testcase_32 AC 2 ms
5,248 KB
testcase_33 AC 3 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
// @formatter:off

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VVVVL = vector<VVVL>;
using VP = vector<P>;
using VVP = vector<vector<P>>;
using VS = vector<string>;
using VC = vector<char>;
using VVC = vector<vector<char>>;
using VD = vector<double>;
using VVD = vector<vector<double>>;
using VVVD = vector<VVD>;
// #define MOD 1000000007
#define MOD 998244353
const int INF = 1000000007;
const long long INFL = (ll)INF * INF;
const int JU_5 = 100000;
const int JU_6 = 1000000;
const ll JU_9 = 1000000000;
const ll JU_18 = JU_9 * JU_9;

template <class T, class C>
bool chmax(T& a, C b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T, class C>
bool chmin(T& a, C b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T, class C>
T min(T a, C b) { return a <= b ? a : T(b); }

template <class T, class C>
T max(T a, C b) { return a >= b ? a : T(b); }

template <typename T>
ostream& operator<<(ostream& os, const deque<T>& vec) {
    for (int i = 0; i < vec.size() - 1; i++) os << vec[i] << " ";
    if (vec.size()) os << vec.back();
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& vec) {
    os << "{";
    for (auto v : vec) os << v << ",";
    os << "}";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& vec) {
    os << "{";
    for (auto v : vec) os << v << ",";
    os << "}";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& vec) {
    os << "{";
    for (auto v : vec) os << v << ",";
    os << "}";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const unordered_multiset<T>& vec) {
    os << "{";
    for (auto v : vec) os << v << ",";
    os << "}";
    return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& pa) {
    os << "(" << pa.first << "," << pa.second << ")";
    return os;
}
template <typename TK, typename TV>
ostream& operator<<(ostream& os, const map<TK, TV>& mp) {
    os << "{";
    for (auto v : mp) os << v.first << "=>" << v.second << ",";
    os << "}";
    return os;
}
template <typename TK, typename TV>
ostream& operator<<(ostream& os, const unordered_map<TK, TV>& mp) {
    os << "{";
    for (auto v : mp) os << v.first << "=>" << v.second << ",";
    os << "}";
    return os;
}

struct mint {
    ll x;
    int mod;
    mint(ll x = 0, int mod = MOD) : x((x % mod + mod) % mod), mod(mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
using VMI = vector<mint>;
using VVMI = vector<vector<mint>>;

void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T>& vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl
         << flush;
}
template <class T>
void print(vector<vector<T>>& df) {
    for (auto& vec : df) {
        print(vec);
    }
}

#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

/////////////////////////////////////////////////////////
// @formatter:on

struct Comb {
    int n;
    vector<mint> kaijo;
    vector<mint> gyaku;

    ll r(ll x) {
        while (x % MOD == 0) x /= MOD;
        return x;
    }
    // xの mod 進数
    int rcnt(ll x) {
        if (x <= 0) return 0;
        return rcnt(x / MOD) + x / MOD;
    }

    Comb(int mn) : n(mn + 1), kaijo(mn + 1), gyaku(mn + 1) {
        // mod で割り切れるだけ割ったときの nCm を求められるように, 階乗と逆元を求める
        kaijo[0] = 1;
        for (int i = 1; i < n; i++) {
            kaijo[i] = kaijo[i - 1] * r(i);
        }
        gyaku[n - 1] = kaijo[n - 1].pow(MOD - 2);
        for (int i = n - 1; i > 0; i--) {
            gyaku[i - 1] = gyaku[i] * r(i);
        }
    }

    mint nCm(int n, int m) {
        if (n < m || m < 0) return 0;

        int cnt1 = rcnt(n);
        int cnt2 = rcnt(n - m) + rcnt(m);
        if (cnt1 > cnt2) return mint(0);
        assert(n < kaijo.size());
        assert(m < gyaku.size());
        return kaijo[n] * gyaku[n - m] * gyaku[m];
    }
    mint nPm(int n, int m) {
        if (n < 0 || m > n) return 0;
        if (n == m) return kaijo[n];
        int cnt1 = rcnt(n);
        int cnt2 = rcnt(n - m);
        if (cnt1 > cnt2) return mint(0);
        return kaijo[n] * gyaku[n - m];
    }
    // 重複組合せ. n 種類の中から重複を許し m 個とる
    mint nHm(int n, int m) {
        int l = n + m - 1;
        int r = n - 1;
        if (l < 0 || r < 0) return mint(0);
        return nCm(l, r);
    }
};
int bitcnt(long long x) {
    return __builtin_popcount(x);
}
vector<pair<ll, int>> primeFactorize(ll n) {
    if (n <= 1) {
        return {};
    }
    vector<pair<ll, int>> res;
    ll x = n;

    for (ll i = 2; i * i <= n; i++) {
        if (x == 1) break;
        if (x % i != 0) continue;
        int cnt = 0;

        while (x % i == 0) {
            cnt++;
            x /= i;
        }
        res.emplace_back(i, cnt);
    }
    if (x > 1) {
        res.emplace_back(x, 1);
    }
    return res;
}

bool isHeiho(long long x) {
    long long v = sqrt(x) + 0.1;
    return v * v == x;
}

void _main() {
    int n;
    cin >> n;
    VL a(n);
    rep(i, n) cin >> a[i];
    map<ll, int> mp;
    rep(i, n) {
        srep(j, i + 1, n) {
            ll g = gcd(a[i], a[j]);
            a[i] /= g;
            a[j] /= g;
        }
    }
    // print(a);
    // rep(i, n) {
    //     if (a[i] > 1) {
    //         No;
    //         return;
    //     }
    // }
    rep(i, n) {
        if(a[i]==1)continue;
        if(!isHeiho(a[i])){
            No;return;
        }
    }
    Yes;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    std::cout << std::setprecision(15);
    //////////////////////////////////////////
    int t = 1;
    cin >> t;
    while (t--) _main();

    return 0;
}
0