結果

問題 No.2074 Product is Square ?
ユーザー dn6049949dn6049949
提出日時 2022-09-16 21:54:41
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,848 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 86,576 KB
実行使用メモリ 82,420 KB
最終ジャッジ日時 2023-08-23 15:19:07
合計ジャッジ時間 32,617 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,396 KB
testcase_01 AC 804 ms
79,712 KB
testcase_02 AC 753 ms
80,024 KB
testcase_03 AC 743 ms
80,372 KB
testcase_04 AC 749 ms
80,356 KB
testcase_05 AC 788 ms
79,744 KB
testcase_06 AC 761 ms
79,188 KB
testcase_07 AC 754 ms
79,904 KB
testcase_08 AC 729 ms
80,040 KB
testcase_09 AC 720 ms
79,844 KB
testcase_10 AC 713 ms
79,580 KB
testcase_11 AC 335 ms
79,828 KB
testcase_12 AC 775 ms
81,384 KB
testcase_13 TLE -
testcase_14 AC 505 ms
81,120 KB
testcase_15 AC 334 ms
80,208 KB
testcase_16 AC 813 ms
82,420 KB
testcase_17 TLE -
testcase_18 AC 558 ms
79,976 KB
testcase_19 AC 337 ms
80,164 KB
testcase_20 AC 779 ms
82,028 KB
testcase_21 TLE -
testcase_22 AC 518 ms
80,492 KB
testcase_23 AC 343 ms
80,464 KB
testcase_24 AC 816 ms
81,228 KB
testcase_25 TLE -
testcase_26 AC 547 ms
81,484 KB
testcase_27 AC 320 ms
80,016 KB
testcase_28 AC 821 ms
80,872 KB
testcase_29 TLE -
testcase_30 AC 544 ms
80,952 KB
testcase_31 AC 164 ms
77,976 KB
testcase_32 AC 95 ms
72,316 KB
testcase_33 AC 131 ms
77,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def gcd(a, b):
    while a:
        a, b = b%a, a
    return b


def is_prime(n):
    if n == 2:
        return 1
    if n == 1 or n%2 == 0:
        return 0

    m = n - 1
    lsb = m & -m
    s = lsb.bit_length()-1
    d = m // lsb
    if n < 4759123141:
        test_numbers = [2, 7, 61]
    elif n < 341550071728321:
        test_numbers = [2, 3, 5, 7, 11, 13, 17]
    elif n < 3825123056546413051:
        test_numbers = [2, 3, 5, 7, 11, 13, 17, 19, 23]
    else:
        test_numbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]

    for a in test_numbers:
        if a == n:
            continue
        x = pow(a,d,n)
        r = 0
        if x == 1:
            continue
        while x != m:
            x = pow(x,2,n)
            if x == 1 or r == s:
                return 0
            r += 1
    return 1


def find_prime_factor(n):
    m = max(1,int(n**0.125))

    for c in range(1,n):
        f = lambda a: (pow(a,2,n)+c)%n
        y = 0
        g = q = r = 1
        while g == 1:
            x = y
            for _ in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for _ 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
            y = ys
            while g == 1:
                y = f(y)
                g = gcd(abs(x-y),n)
        if g == n:
            continue
        if is_prime(g):
            return g
        elif is_prime(n//g):
            return n//g
        else:
            n = g


def factorize(n):
    res = {}
    for p in range(2,1000):
        if p*p > n:
            break
        if n%p:
            continue
        s = 0
        while n%p == 0:
            n //= p
            s += 1
        res[p] = s

    while not is_prime(n) and n > 1:
        p = find_prime_factor(n)
        s = 0
        while n%p == 0:
            n //= p
            s += 1
        res[p] = s
    if n > 1:
        res[n] = 1
    return res


def main():
    n = I()
    a = LI()
    s = defaultdict(lambda : 0)
    for i in a:
        f = factorize(i)
        for i,j in f.items():
            s[i] ^= j&1
    if all(si == 0 for si in s.values()):
        print("Yes")
    else:
        print("No")
    return


if __name__ == "__main__":
    for _ in range(I()):
        main()
0