結果

問題 No.2074 Product is Square ?
ユーザー shotoyooshotoyoo
提出日時 2022-09-16 22:44:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 2,673 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 78,532 KB
最終ジャッジ日時 2023-08-23 16:18:49
合計ジャッジ時間 10,628 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,940 KB
testcase_01 AC 107 ms
77,916 KB
testcase_02 AC 102 ms
77,908 KB
testcase_03 AC 105 ms
78,160 KB
testcase_04 AC 107 ms
78,148 KB
testcase_05 AC 105 ms
78,112 KB
testcase_06 AC 105 ms
77,992 KB
testcase_07 AC 105 ms
77,992 KB
testcase_08 AC 106 ms
77,868 KB
testcase_09 AC 107 ms
77,816 KB
testcase_10 AC 110 ms
78,368 KB
testcase_11 AC 375 ms
78,248 KB
testcase_12 AC 353 ms
78,108 KB
testcase_13 AC 556 ms
78,168 KB
testcase_14 AC 379 ms
78,080 KB
testcase_15 AC 371 ms
77,952 KB
testcase_16 AC 354 ms
78,404 KB
testcase_17 AC 551 ms
78,292 KB
testcase_18 AC 383 ms
78,320 KB
testcase_19 AC 320 ms
78,272 KB
testcase_20 AC 302 ms
78,308 KB
testcase_21 AC 543 ms
78,204 KB
testcase_22 AC 346 ms
78,128 KB
testcase_23 AC 329 ms
78,180 KB
testcase_24 AC 346 ms
78,068 KB
testcase_25 AC 415 ms
78,004 KB
testcase_26 AC 291 ms
78,108 KB
testcase_27 AC 361 ms
78,532 KB
testcase_28 AC 348 ms
78,388 KB
testcase_29 AC 370 ms
78,348 KB
testcase_30 AC 301 ms
78,048 KB
testcase_31 AC 91 ms
76,180 KB
testcase_32 AC 87 ms
72,152 KB
testcase_33 AC 108 ms
77,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, random
input = lambda : sys.stdin.readline().rstrip()


write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18
LI = lambda : list(map(int, input().split())); II=lambda : int(input())
def debug(_l_):
    for s in _l_.split():
        print(f"{s}={eval(s)}", end=" ")
    print()
def dlist(*l, fill=0):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [dlist(*ll, fill=fill) for _ in range(l[0])]

def isqrt(n):
    """x*x<=nなる最大のx
    """
    x,y = n, (n+1)//2
    while y<x:
        x,y = y, (y + n//y) // 2
    return x
from math import gcd
import random
def is_prime(n):
    """miller_rabinによる素数判定
    ※ 1は素数と扱う
    """
    l = [2,3,5,7,11,13,17,19,23,29,31,37]
    if n==1 or n in l:
        return True
    d = n-1
    s = 0
    while d%2==0:
        s += 1
        d //= 2
    for a in l:
        v = pow(a,d,n)
        if v==1 or v==n-1:
            continue
        for _ in range(s):
            v = v*v % n
            if v==n-1:
                break
        else:
            return False
    return True
def rho(n):
    """nを割り切る3以上の素数を返す(素数のときnを返す)
    """
    if is_prime(n):
        return n
    while True:
        x = y = random.randint(1,n-1)
        g = 1
        while g==1:
            x = (x*x - 3) % n
            y = (y*y - 3) % n
            y = (y*y - 3) % n
            g = gcd((x-y), n)
        if g>1:
            return rho(g)
def factor(n):
    """高速な素因数分解
    """
    n0 = n
    if n in _d:
        return _d[n0]
    if n==1:
        return {}
    f = is_prime(n)
    if f:
        _d[n0] = {n:1}
        return {n:1}
    ans = {}
    while n%2==0:
        ans.setdefault(2, 0)
        ans[2] += 1
        n //= 2
    v = rho(n)
    while v!=n and n>1:
        ans.setdefault(v, 0)
        while n%v==0:
            n //= v
            ans[v] += 1
        if n>3 and is_prime(n):
            ans.setdefault(n,0)
            ans[n] += 1
            _d[n0] = ans
            return ans
        v = rho(n)
    if n>1:
        ans.setdefault(n, 0)
        ans[n] += 1
    _d[n0] = ans
    return ans
t = II()
_d = {}
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    from math import gcd
    for i in range(n):
        for j in range(i+1,n):
            g = gcd(a[i], a[j])
            a[i] //= g
            a[j] //= g
        if isqrt(a[i])**2!=a[i]:
            ans = 0
            break
    else:
        ans = 1
    pans(ans)
0