結果

問題 No.2074 Product is Square ?
ユーザー pockynypockyny
提出日時 2022-09-17 20:51:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 495 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 567 ms
コンパイル使用メモリ 69,276 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-23 17:53:42
合計ジャッジ時間 6,360 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 5 ms
4,376 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 AC 6 ms
4,376 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 5 ms
4,504 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 68 ms
4,380 KB
testcase_12 AC 153 ms
4,376 KB
testcase_13 AC 495 ms
4,376 KB
testcase_14 AC 160 ms
4,380 KB
testcase_15 AC 68 ms
4,380 KB
testcase_16 AC 159 ms
4,376 KB
testcase_17 AC 493 ms
4,380 KB
testcase_18 AC 154 ms
4,376 KB
testcase_19 AC 67 ms
4,376 KB
testcase_20 AC 157 ms
4,380 KB
testcase_21 AC 490 ms
4,380 KB
testcase_22 AC 155 ms
4,376 KB
testcase_23 AC 67 ms
4,376 KB
testcase_24 AC 157 ms
4,376 KB
testcase_25 AC 495 ms
4,376 KB
testcase_26 AC 152 ms
4,376 KB
testcase_27 AC 66 ms
4,376 KB
testcase_28 AC 156 ms
4,376 KB
testcase_29 AC 491 ms
4,376 KB
testcase_30 AC 156 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
    if(a<b) swap(a,b);
    if(b==0) return a;
    return gcd(a%b,b);
}

bool isSquare(ll x){
    ll le = 0,ri = 1000000000;
    while(ri - le>1){
        ll mid = (le + ri)/2;
        if(mid*mid>=x) ri = mid;
        else le = mid;
    }
    return ri*ri==x;
}

ll a[2010];
int main(){
    int t; cin >> t;
    while(t){
        t--;
        int i,j,n; cin >> n;
        for(i=0;i<n;i++) cin >> a[i];
        for(i=0;i<n;i++){
            for(j=i + 1;j<n;j++){
                ll g = gcd(a[i],a[j]);
                a[i] /= g; a[j] /= g;
            }
        }
        bool f = true;
        for(i=0;i<n;i++){
            if(!isSquare(a[i])) f = false;
        }
        if(f) cout << "Yes\n";
        else cout << "No\n";
    }
}
0