結果

問題 No.2074 Product is Square ?
ユーザー qibqib
提出日時 2023-01-11 18:56:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 436 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 77,780 KB
最終ジャッジ日時 2024-06-01 22:09:43
合計ジャッジ時間 8,308 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
54,060 KB
testcase_01 AC 58 ms
68,448 KB
testcase_02 AC 56 ms
67,884 KB
testcase_03 AC 56 ms
67,708 KB
testcase_04 AC 56 ms
68,564 KB
testcase_05 AC 56 ms
67,640 KB
testcase_06 AC 55 ms
67,640 KB
testcase_07 AC 57 ms
66,860 KB
testcase_08 AC 54 ms
67,272 KB
testcase_09 AC 53 ms
66,352 KB
testcase_10 AC 53 ms
67,256 KB
testcase_11 AC 287 ms
68,644 KB
testcase_12 AC 264 ms
69,724 KB
testcase_13 AC 420 ms
72,508 KB
testcase_14 AC 290 ms
69,388 KB
testcase_15 AC 287 ms
68,800 KB
testcase_16 AC 266 ms
69,384 KB
testcase_17 AC 430 ms
71,588 KB
testcase_18 AC 296 ms
69,324 KB
testcase_19 AC 286 ms
68,220 KB
testcase_20 AC 274 ms
68,108 KB
testcase_21 AC 436 ms
71,908 KB
testcase_22 AC 291 ms
68,464 KB
testcase_23 AC 289 ms
68,592 KB
testcase_24 AC 268 ms
69,744 KB
testcase_25 AC 432 ms
70,248 KB
testcase_26 AC 292 ms
67,200 KB
testcase_27 AC 290 ms
68,500 KB
testcase_28 AC 265 ms
69,832 KB
testcase_29 AC 418 ms
69,712 KB
testcase_30 AC 289 ms
69,376 KB
testcase_31 AC 44 ms
62,452 KB
testcase_32 AC 37 ms
53,996 KB
testcase_33 AC 83 ms
77,780 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