結果

問題 No.2074 Product is Square ?
ユーザー qibqib
提出日時 2023-01-11 18:56:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 559 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 78,188 KB
最終ジャッジ日時 2023-08-24 00:47:24
合計ジャッジ時間 11,753 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,680 KB
testcase_01 AC 112 ms
78,064 KB
testcase_02 AC 111 ms
77,964 KB
testcase_03 AC 115 ms
77,780 KB
testcase_04 AC 110 ms
77,968 KB
testcase_05 AC 112 ms
78,084 KB
testcase_06 AC 109 ms
78,108 KB
testcase_07 AC 109 ms
77,736 KB
testcase_08 AC 109 ms
77,776 KB
testcase_09 AC 107 ms
77,684 KB
testcase_10 AC 107 ms
78,024 KB
testcase_11 AC 378 ms
77,980 KB
testcase_12 AC 357 ms
78,024 KB
testcase_13 AC 556 ms
78,104 KB
testcase_14 AC 383 ms
78,072 KB
testcase_15 AC 376 ms
77,900 KB
testcase_16 AC 360 ms
77,648 KB
testcase_17 AC 559 ms
78,188 KB
testcase_18 AC 389 ms
78,128 KB
testcase_19 AC 379 ms
78,084 KB
testcase_20 AC 354 ms
77,812 KB
testcase_21 AC 554 ms
78,028 KB
testcase_22 AC 377 ms
77,728 KB
testcase_23 AC 379 ms
77,924 KB
testcase_24 AC 359 ms
77,908 KB
testcase_25 AC 544 ms
78,088 KB
testcase_26 AC 378 ms
78,056 KB
testcase_27 AC 372 ms
77,980 KB
testcase_28 AC 362 ms
77,840 KB
testcase_29 AC 549 ms
77,744 KB
testcase_30 AC 386 ms
78,056 KB
testcase_31 AC 98 ms
76,688 KB
testcase_32 AC 88 ms
71,540 KB
testcase_33 AC 134 ms
78,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import math

def is_square(x):
  ok = 10 ** 9
  ng = 0
  while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if mid * mid >= x:
      ok = mid
    else:
      ng = mid

  return ok * ok == x

t = int(input())
for _ in range(t):
  n = int(input())
  a = list(map(int, input().split()))
  for i in range(n - 1):
    for j in range(i + 1, n):
      g = math.gcd(a[i], a[j])
      a[i] //= g
      a[j] //= g

  if all(is_square(x) for x in a):
    print("Yes")
  else:
    print("No")
0