結果

問題 No.2074 Product is Square ?
ユーザー 👑 KazunKazun
提出日時 2022-09-16 22:38:29
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,824 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 88,164 KB
最終ジャッジ日時 2023-08-23 16:13:56
合計ジャッジ時間 14,473 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,764 KB
testcase_01 AC 873 ms
82,276 KB
testcase_02 AC 837 ms
81,444 KB
testcase_03 AC 864 ms
82,608 KB
testcase_04 AC 853 ms
81,884 KB
testcase_05 AC 905 ms
81,992 KB
testcase_06 AC 879 ms
82,128 KB
testcase_07 AC 856 ms
81,836 KB
testcase_08 AC 833 ms
81,904 KB
testcase_09 AC 806 ms
81,800 KB
testcase_10 AC 819 ms
81,372 KB
testcase_11 AC 467 ms
82,280 KB
testcase_12 AC 939 ms
83,276 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#Miller-Rabinの素数判定法
def Miller_Rabin_Primality_Test(N,Times=20):
    """ Miller-Rabin による整数 N の素数判定を行う.

    N: 整数
    ※ True は正確には Probably True である ( False は 確定 False ).
    """
    from random import randint as ri

    if N==2: return True

    if N==1 or N%2==0: return False

    q=N-1
    k=0
    while q&1==0:
        k+=1
        q>>=1

    for _ in range(Times):
        m=ri(2,N-1)
        y=pow(m,q,N)
        if y==1:
            continue

        flag=True
        for i in range(k):
            if (y+1)%N==0:
                flag=False
                break

            y*=y
            y%=N

        if flag:
            return False
    return True

#ポラード・ローアルゴリズムによって素因数を発見する
#参考元:https://judge.yosupo.jp/submission/6131
def Find_Factor_Rho(N):
    if N==1:
        return 1
    from math import gcd
    m=1<<(N.bit_length()//8+1)

    for c in range(1,99):
        f=lambda x:(x*x+c)%N
        y,r,q,g=2,1,1,1
        while g==1:
            x=y
            for i in range(r):
                y=f(y)
            k=0
            while k<r and g==1:
                for i in range(min(m, r - k)):
                    y=f(y)
                    q=q*abs(x - y)%N
                g=gcd(q,N)
                k+=m
            r <<=1

        if g<N:
            if Miller_Rabin_Primality_Test(g):
                return g
            elif Miller_Rabin_Primality_Test(N//g):
                return N//g
    return N

#ポラード・ローアルゴリズムによる素因数分解
#参考元:https://judge.yosupo.jp/submission/6131
def Pollard_Rho_Prime_Factorization(N):
    I=2
    res=[]
    while I*I<=N:
        if N%I==0:
            k=0
            while N%I==0:
                k+=1
                N//=I
            res.append([I,k])

        I+=1+(I%2)

        if I!=101 or N<2**20:
            continue

        while N>1:
            if Miller_Rabin_Primality_Test(N):
                res.append([N,1])
                N=1
            else:
                j=Find_Factor_Rho(N)
                k=0
                while N%j==0:
                    N//=j
                    k+=1
                res.append([j,k])
    if N>1:
        res.append([N,1])
    res.sort(key=lambda x:x[0])
    return res
#==================================================
from collections import defaultdict

def solve():
    N=int(input())
    A=list(map(int,input().split()))

    D=defaultdict(int)
    for a in A:
        for p,e in Pollard_Rho_Prime_Factorization(a):
            D[p]+=e

    for p in D:
        if D[p]%2==1:
            return False
    return True

#==================================================
T=int(input())
for _ in range(T):
    print("Yes" if solve() else "No")
0