結果

問題 No.2074 Product is Square ?
ユーザー ygd.ygd.
提出日時 2022-09-16 23:18:59
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,393 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 81,132 KB
最終ジャッジ日時 2023-08-23 16:41:08
合計ジャッジ時間 13,281 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,548 KB
testcase_01 AC 782 ms
80,792 KB
testcase_02 AC 727 ms
79,884 KB
testcase_03 AC 728 ms
79,244 KB
testcase_04 AC 744 ms
79,500 KB
testcase_05 AC 786 ms
79,344 KB
testcase_06 AC 776 ms
80,144 KB
testcase_07 AC 773 ms
79,512 KB
testcase_08 AC 724 ms
79,980 KB
testcase_09 AC 720 ms
80,872 KB
testcase_10 AC 705 ms
79,684 KB
testcase_11 AC 237 ms
78,828 KB
testcase_12 AC 706 ms
79,824 KB
testcase_13 TLE -
testcase_14 AC 442 ms
79,496 KB
testcase_15 AC 225 ms
79,004 KB
testcase_16 WA -
testcase_17 TLE -
testcase_18 AC 483 ms
80,028 KB
testcase_19 AC 227 ms
79,072 KB
testcase_20 AC 732 ms
80,424 KB
testcase_21 TLE -
testcase_22 AC 446 ms
80,008 KB
testcase_23 AC 229 ms
79,020 KB
testcase_24 AC 766 ms
80,372 KB
testcase_25 TLE -
testcase_26 AC 467 ms
79,888 KB
testcase_27 AC 225 ms
79,112 KB
testcase_28 AC 741 ms
79,896 KB
testcase_29 TLE -
testcase_30 AC 478 ms
79,432 KB
testcase_31 AC 187 ms
78,200 KB
testcase_32 RE -
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
import math
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
from collections import defaultdict 
#from collections import deque
#import copy #DeepCopy: hoge = [_[:] for _ in hogehoge]
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
 
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1:
            continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1:
                return 0
            t <<= 1
    return 1

#無断使用すいません
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    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:
                ys = y
                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:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g):
                return g
            elif isPrimeMR(n // g):
                return n // g
            return findFactorRho(g)
 
 
def primeFactor(n): #これを実行
    i = 2
    ret = {}
    rhoFlg = 0
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k:
            ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k
 
    if n > 1:
        ret[n] = 1
    if rhoFlg:
        ret = {x: ret[x] for x in sorted(ret)}
    return ret


#高速素因数分解を用いた約数全列挙
import itertools
def factorization_fast(x):
    P = primeFactor(x)
    base = []
    L = []
    for p in P:
        base.append(p)
        temp = [i for i in range(P[p]+1)]
        L.append(temp)
    ret = []
    for T in itertools.product(*L):
        val = 1
        for i,t in enumerate(T):
            val *= pow(base[i],t)
        ret.append(val)
    ret.sort() #必要ならソート
    return ret


def main():
    T = int(input())
    for _ in range(T):
        N = int(input())
        A = list(map(int,input().split()))
        dic = defaultdict(int)
        for a in A:
            PL = primeFactor(a)
            for p,num in PL.items():
                dic[p] ^= num%2
        
        if max(dic.values()) == 0:
            print('Yes')
        else:
            print('No')



if __name__ == '__main__':
    main()
0