結果

問題 No.144 エラトステネスのざる
ユーザー simansiman
提出日時 2015-04-04 23:04:04
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 539 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 11,240 KB
実行使用メモリ 20,160 KB
最終ジャッジ日時 2023-09-17 04:29:50
合計ジャッジ時間 5,347 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
19,812 KB
testcase_01 AC 94 ms
15,272 KB
testcase_02 AC 95 ms
15,312 KB
testcase_03 AC 99 ms
15,136 KB
testcase_04 AC 94 ms
15,216 KB
testcase_05 AC 95 ms
15,372 KB
testcase_06 AC 107 ms
15,668 KB
testcase_07 AC 107 ms
15,964 KB
testcase_08 AC 108 ms
15,972 KB
testcase_09 AC 106 ms
15,908 KB
testcase_10 AC 107 ms
15,716 KB
testcase_11 AC 107 ms
15,856 KB
testcase_12 AC 106 ms
15,720 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

class Integer
  def divisor_list
    return [] if self <= 0
    return [1] if self == 1

    prime_division.map{|e| [*(0..e.last)].map{|v| e.first ** v }}.inject{|res, e| res.map{|t| e.map{|v| t * v}}.flatten}.sort
  end
end

class Yukicoder
  def initialize
    n, p0 = gets.chomp.split(' ').map(&:to_f)
    n = n.to_i

    rate = 0.0

    2.upto(n) do |num|
      if num.prime?
        rate += 1
      else
        rate += (1 - p0) ** (num.divisor_list.size - 2)
      end
    end

    puts rate
  end
end

Yukicoder.new
0