結果

問題 No.2074 Product is Square ?
ユーザー AngrySadEightAngrySadEight
提出日時 2022-09-14 20:14:23
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 499 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 686 ms
使用メモリ 3,564 KB
最終ジャッジ日時 2023-01-08 06:48:07
合計ジャッジ時間 7,554 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,384 KB
testcase_01 AC 5 ms
3,540 KB
testcase_02 AC 6 ms
3,528 KB
testcase_03 AC 5 ms
3,556 KB
testcase_04 AC 5 ms
3,476 KB
testcase_05 AC 5 ms
3,540 KB
testcase_06 AC 5 ms
3,440 KB
testcase_07 AC 5 ms
3,536 KB
testcase_08 AC 5 ms
3,444 KB
testcase_09 AC 5 ms
3,448 KB
testcase_10 AC 5 ms
3,380 KB
testcase_11 AC 68 ms
3,552 KB
testcase_12 AC 154 ms
3,548 KB
testcase_13 AC 497 ms
3,448 KB
testcase_14 AC 159 ms
3,452 KB
testcase_15 AC 67 ms
3,436 KB
testcase_16 AC 159 ms
3,532 KB
testcase_17 AC 499 ms
3,436 KB
testcase_18 AC 156 ms
3,508 KB
testcase_19 AC 68 ms
3,388 KB
testcase_20 AC 160 ms
3,384 KB
testcase_21 AC 498 ms
3,436 KB
testcase_22 AC 156 ms
3,564 KB
testcase_23 AC 68 ms
3,496 KB
testcase_24 AC 159 ms
3,388 KB
testcase_25 AC 498 ms
3,456 KB
testcase_26 AC 154 ms
3,540 KB
testcase_27 AC 67 ms
3,540 KB
testcase_28 AC 157 ms
3,544 KB
testcase_29 AC 497 ms
3,436 KB
testcase_30 AC 156 ms
3,384 KB
testcase_31 AC 1 ms
3,440 KB
testcase_32 AC 2 ms
3,444 KB
testcase_33 AC 3 ms
3,536 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