結果

問題 No.36 素数が嫌い!
ユーザー code-devocode-devo
提出日時 2016-01-20 05:22:43
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,040 ms / 5,000 ms
コード長 315 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 11,204 KB
実行使用メモリ 35,684 KB
最終ジャッジ日時 2023-09-09 07:32:14
合計ジャッジ時間 27,757 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 948 ms
27,928 KB
testcase_01 AC 1,437 ms
29,404 KB
testcase_02 AC 91 ms
15,304 KB
testcase_03 AC 92 ms
15,160 KB
testcase_04 AC 92 ms
15,320 KB
testcase_05 AC 101 ms
15,440 KB
testcase_06 AC 102 ms
15,584 KB
testcase_07 AC 104 ms
15,620 KB
testcase_08 AC 96 ms
15,316 KB
testcase_09 AC 97 ms
15,536 KB
testcase_10 AC 100 ms
15,396 KB
testcase_11 AC 752 ms
25,816 KB
testcase_12 AC 2,028 ms
35,156 KB
testcase_13 AC 2,020 ms
35,376 KB
testcase_14 AC 1,234 ms
29,336 KB
testcase_15 AC 90 ms
15,224 KB
testcase_16 AC 90 ms
15,312 KB
testcase_17 AC 91 ms
15,496 KB
testcase_18 AC 92 ms
15,388 KB
testcase_19 AC 929 ms
27,940 KB
testcase_20 AC 2,040 ms
35,684 KB
testcase_21 AC 1,504 ms
30,328 KB
testcase_22 AC 1,619 ms
31,492 KB
testcase_23 AC 906 ms
27,816 KB
testcase_24 AC 1,101 ms
29,256 KB
testcase_25 AC 1,120 ms
29,336 KB
testcase_26 AC 1,341 ms
29,480 KB
testcase_27 AC 1,605 ms
31,392 KB
testcase_28 AC 1,378 ms
29,360 KB
testcase_29 AC 1,783 ms
33,300 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

def pn_div(n, pn_from = nil)
  pns = Prime.each(Math.sqrt(n).to_i).to_a
  pns.select!{|pn| pn >= pn_from} if pn_from
  pns.each do |pn|
    q, r = n.divmod(pn)
    return pn, q if r == 0
  end
  return nil
end


N = gets.to_i
n1, n2 = pn_div(N)
n1, n2 = pn_div(n2, n1) if n1
puts n1 ? "YES" : "NO"
0