結果

問題 No.2074 Product is Square ?
ユーザー simansiman
提出日時 2022-09-19 15:37:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 819 ms / 2,000 ms
コード長 459 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 11,460 KB
実行使用メモリ 15,588 KB
最終ジャッジ日時 2023-08-23 18:55:56
合計ジャッジ時間 16,513 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
15,200 KB
testcase_01 AC 100 ms
15,572 KB
testcase_02 AC 102 ms
15,476 KB
testcase_03 AC 105 ms
15,344 KB
testcase_04 AC 103 ms
15,580 KB
testcase_05 AC 101 ms
15,472 KB
testcase_06 AC 103 ms
15,404 KB
testcase_07 AC 101 ms
15,456 KB
testcase_08 AC 104 ms
15,588 KB
testcase_09 AC 103 ms
15,584 KB
testcase_10 AC 103 ms
15,580 KB
testcase_11 AC 532 ms
15,580 KB
testcase_12 AC 519 ms
15,332 KB
testcase_13 AC 817 ms
15,272 KB
testcase_14 AC 567 ms
15,280 KB
testcase_15 AC 531 ms
15,496 KB
testcase_16 AC 530 ms
15,396 KB
testcase_17 AC 819 ms
15,580 KB
testcase_18 AC 568 ms
15,404 KB
testcase_19 AC 527 ms
15,500 KB
testcase_20 AC 525 ms
15,268 KB
testcase_21 AC 800 ms
15,492 KB
testcase_22 AC 566 ms
15,556 KB
testcase_23 AC 529 ms
15,332 KB
testcase_24 AC 527 ms
15,332 KB
testcase_25 AC 805 ms
15,304 KB
testcase_26 AC 562 ms
15,272 KB
testcase_27 AC 529 ms
15,336 KB
testcase_28 AC 523 ms
15,364 KB
testcase_29 AC 809 ms
15,268 KB
testcase_30 AC 568 ms
15,392 KB
testcase_31 AC 96 ms
15,276 KB
testcase_32 AC 93 ms
15,208 KB
testcase_33 AC 97 ms
15,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

T = gets.to_i

def f(x)
  ok = 1
  ng = x

  while (ok - ng).abs >= 2
    v = (ok + ng) / 2

    if v ** 2 <= x
      ok = v
    else
      ng = v
    end
  end

  ok ** 2 == x
end

T.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)

  0.upto(n - 2) do |i|
    (i + 1).upto(n - 1) do |j|
      gcd = a[i].gcd(a[j])
      a[i] /= gcd
      a[j] /= gcd
    end
  end

  if a.all? { |v| f(v) }
    puts 'Yes'
  else
    puts 'No'
  end
end
0