結果

問題 No.2074 Product is Square ?
ユーザー t98slidert98slider
提出日時 2022-09-16 22:04:26
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 1,001 ms / 2,000 ms
コード長 983 bytes
コンパイル時間 1,423 ms
使用メモリ 6,952 KB
最終ジャッジ日時 2023-01-11 07:05:19
合計ジャッジ時間 10,742 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
4,900 KB
testcase_01 AC 6 ms
4,900 KB
testcase_02 AC 6 ms
6,952 KB
testcase_03 AC 7 ms
4,904 KB
testcase_04 AC 6 ms
4,900 KB
testcase_05 AC 7 ms
4,900 KB
testcase_06 AC 6 ms
4,900 KB
testcase_07 AC 6 ms
4,904 KB
testcase_08 AC 7 ms
4,908 KB
testcase_09 AC 6 ms
4,900 KB
testcase_10 AC 6 ms
4,900 KB
testcase_11 AC 95 ms
6,948 KB
testcase_12 AC 225 ms
4,904 KB
testcase_13 AC 998 ms
6,948 KB
testcase_14 AC 190 ms
4,900 KB
testcase_15 AC 94 ms
4,900 KB
testcase_16 AC 228 ms
6,952 KB
testcase_17 AC 1,001 ms
4,900 KB
testcase_18 AC 194 ms
6,952 KB
testcase_19 AC 94 ms
4,904 KB
testcase_20 AC 228 ms
6,952 KB
testcase_21 AC 996 ms
6,948 KB
testcase_22 AC 191 ms
6,948 KB
testcase_23 AC 97 ms
4,904 KB
testcase_24 AC 226 ms
4,904 KB
testcase_25 AC 998 ms
4,900 KB
testcase_26 AC 191 ms
4,904 KB
testcase_27 AC 94 ms
4,904 KB
testcase_28 AC 228 ms
4,904 KB
testcase_29 AC 996 ms
4,900 KB
testcase_30 AC 192 ms
4,900 KB
testcase_31 AC 1 ms
4,904 KB
testcase_32 AC 2 ms
4,900 KB
testcase_33 AC 3 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int T;
    cin >> T;
    //vが平方数であるか
    auto f = [&](ll v){
        if(v == 1)return true;
        ll ng = 1, ok = 1000000000, mid;
        while(ng + 1 < ok){
            mid = (ng + ok) / 2;
            if(mid * mid >= v)ok = mid;
            else ng = mid;
        }
        return (ok * ok == v);
    };
    while(T--){
        int n;
        cin >> n;
        vector<ll> a(n);
        for(auto &&v:a)cin >> v;
        sort(a.begin(), a.end());
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i == j)continue;
                ll g = __gcd(a[i], a[j]);
                a[i] /= g, a[j] /= g;
            }
        }
        bool ans = true;
        for(int i = 0; i < n; i++){
            if(!f(a[i])){
                ans = false;
                break;
            }
        }
        cout << (ans ? "Yes" : "No") << '\n';
    }
}
0