結果

問題 No.2074 Product is Square ?
ユーザー AngrySadEightAngrySadEight
提出日時 2022-09-14 20:14:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 499 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 771 ms
コンパイル使用メモリ 76,760 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 18:23:26
合計ジャッジ時間 6,915 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

ll my_gcd(ll a, ll b){
    ll ret;
    if (a < b){
        swap(a, b);
    }
    if (b == 0){
        ret = a;
    }
    else{
        ret = my_gcd(b, a % b);
    }
    return ret;
}

bool is_square(ll a){
    ll left = 0;
    ll right = 1000000001;
    bool ret = false;
    while(right - left > 1){
        ll center = (left + right) / 2;
        if (center * center == a){
            ret = true;
            break;
        }
        else if (center * center > a){
            right = center;
        }
        else{
            left = center;
        }
    }
    return ret;
}

int main(){
    int T;
    cin >> T;
    while(T--){
        int N;
        cin >> N;
        vector<ll> A(N);
        for (int i = 0; i < N; i++){
            cin >> A[i];
        }
        for (int i = 0; i < N; i++){
            for (int j = i + 1; j < N; j++){
                ll g = my_gcd(A[i], A[j]);
                A[i] /= g;
                A[j] /= g;
            }
        }
        bool square = true;
        for (int i = 0; i < N; i++){
            if (!is_square(A[i])) square = false;
        }
        if (square) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}
0