結果

問題 No.2074 Product is Square ?
ユーザー hiro71687khiro71687k
提出日時 2023-03-03 21:30:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 501 ms / 2,000 ms
コード長 1,476 bytes
コンパイル時間 4,377 ms
コンパイル使用メモリ 262,916 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 01:23:37
合計ジャッジ時間 10,816 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=double;
ld pie=3.14159265359;
ll mod=998244353;
long long inf=100000000000000001;
ll gcd(ll a, ll b) {
	a = abs(a); b = abs(b);
	if (a < b)swap(a, b);
	while (b) {
	    ll r=a%b;
        a=b;
	    b=r;
	}
	return a;
}
int main(){
    ll t;
    cin >> t;
    for (ll o = 0; o < t; o++)
    {
        ll n;
        cin >> n;
        vector<ll>a(n);
        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        for (ll i = 0; i < n; i++)
        {
            for (ll j = i+1; j < n; j++)
            {
                ll x=gcd(a[i],a[j]);
                a[i]/=x;
                a[j]/=x;
            }
        }
        bool ok=true;
        for (ll i = 0; i < n; i++)
        {
            ll left=0,right=a[i]+1;
            while (right-left>1)
            {
                ll mid=(right+left)/2;
                ll y=0;
                if (a[i]%mid>=1)
                {
                    y=1;
                }
                if (mid>a[i]/mid+y)
                {
                    right=mid;
                }else{
                    left=mid;
                }
            }
            if (left*left!=a[i])
            {
                ok=false;
            }
        }
        if (ok)
        {
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        
    }
    
}
0