結果

問題 No.2074 Product is Square ?
ユーザー srjywrdnprkt
提出日時 2023-06-11 05:10:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 106,344 KB
最終ジャッジ日時 2025-02-14 01:32:21
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

ll isqrt(ll s){
    ll l=0, r=3e9, c;
    while(r-l>1){
        c = (l+r)/2;
        if (c*c <= s) l = c;
        else r = c;
    }
    return l;
}

void solve(){
    ll N, g;
    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++){
            g = gcd(A[i], A[j]);
            A[i] /= g; A[j] /= g;
        }
    }
    for (int i=0; i<N; i++){
        g = isqrt(A[i]);
        if (g * g != A[i]){
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main(){

    int T;
    cin >> T;
    while(T){
        T--;
        solve();
    }

    return 0;
}
0