結果

問題 No.2074 Product is Square ?
ユーザー みここみここ
提出日時 2022-12-13 00:31:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,210 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 81,052 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 13:48:55
合計ジャッジ時間 44,475 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
5,248 KB
testcase_01 AC 1,115 ms
5,376 KB
testcase_02 AC 1,145 ms
5,376 KB
testcase_03 AC 1,125 ms
5,376 KB
testcase_04 AC 1,139 ms
5,376 KB
testcase_05 AC 1,124 ms
5,376 KB
testcase_06 AC 1,113 ms
5,376 KB
testcase_07 AC 1,123 ms
5,376 KB
testcase_08 AC 1,185 ms
5,376 KB
testcase_09 AC 1,115 ms
5,376 KB
testcase_10 AC 1,112 ms
5,376 KB
testcase_11 AC 1,444 ms
5,376 KB
testcase_12 AC 1,441 ms
5,376 KB
testcase_13 AC 1,485 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 1,450 ms
5,376 KB
testcase_16 AC 1,466 ms
5,376 KB
testcase_17 AC 1,486 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 1,440 ms
5,376 KB
testcase_20 AC 1,455 ms
5,376 KB
testcase_21 AC 1,465 ms
5,376 KB
testcase_22 AC 1,544 ms
5,376 KB
testcase_23 AC 1,458 ms
5,376 KB
testcase_24 AC 1,490 ms
5,376 KB
testcase_25 AC 1,500 ms
5,376 KB
testcase_26 AC 1,543 ms
5,376 KB
testcase_27 AC 1,433 ms
5,376 KB
testcase_28 AC 1,470 ms
5,376 KB
testcase_29 AC 1,490 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 13 ms
5,376 KB
testcase_33 AC 1,488 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long gcd(long long n, long long m)
{
    if (m == 0)
    {
        return n;
    }
    return gcd(m, n % m);
}

std::vector<int> enum_prime(int n) // containing n
{
    std::vector<int> res;
    if (n <= 1)
    {
        return res;
    }
    std::vector<bool> p(n + 1);
    fill(p.begin() + 2, p.end(), true);
    for (int i = 2; i <= n; i++)
    {
        if (p[i])
        {
            res.push_back(i);
            for (int j = i * 2; j <= n; j += i)
            {
                p[j] = false;
            }
        }
    }
    return res;
}

bool is_square(ll x)
{
    ll left = -1, right = 1000000001;
    while(right - left > 1)
    {
        ll mid = (right + left) / 2;
        if(mid * mid >= x)
        {
            right = mid;
        }
        else
        {
            left = mid;
        }
    }
    return right * right == x;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> prime = enum_prime(1000000);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        bool b[1000005]{0};
        ll a[1005];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            for (int p : prime)
            {
                if(a[i] % p == 0)
                {
                    while (a[i] % (p * p) == 0)
                    {
                        a[i] /= p * p;
                    }
                    if (a[i] % p == 0)
                    {
                        a[i] /= p;
                        b[p] ^= 1;
                    }
                }
            }
            if(is_square(a[i]))
            {
                a[i] = 1;
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                ll g = gcd(a[i], a[j]);
                a[i] /= g;
                a[j] /= g;
            }
        }
        bool f = false;
        for (int p : prime)
        {
            f |= b[p];
        }
        for (int i = 0; i < n; i++)
        {
            f |= (a[i] > 1);
        }
        cout << (!f ? "Yes\n" : "No\n");
    }
}
0