結果

問題 No.144 エラトステネスのざる
ユーザー hytkxdhytkxd
提出日時 2023-08-31 22:51:02
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 537 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 11,268 KB
実行使用メモリ 23,524 KB
最終ジャッジ日時 2023-08-31 22:51:22
合計ジャッジ時間 18,289 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,180 KB
testcase_01 AC 82 ms
15,328 KB
testcase_02 AC 80 ms
15,192 KB
testcase_03 AC 82 ms
15,332 KB
testcase_04 AC 82 ms
15,208 KB
testcase_05 AC 81 ms
15,388 KB
testcase_06 AC 83 ms
15,344 KB
testcase_07 AC 84 ms
15,520 KB
testcase_08 AC 83 ms
15,656 KB
testcase_09 AC 82 ms
15,552 KB
testcase_10 AC 80 ms
15,308 KB
testcase_11 AC 79 ms
15,384 KB
testcase_12 AC 82 ms
15,176 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/local/bin/ruby
class EratosthenesLikeSieve
  def initialize(*arg)
    @n,@k = arg
    @sigma = Array.new(@n+1,0)
    eratosthenes
  end

  private
  def eratosthenes
    (2..@n).each do |i|
      last = @n/i
      (2..last).each do |j|
        @sigma[j*i]+=1
      end
    end
  end
  public

  def ans
    r = 0
    pb = 1-@k
    (2..@n).each do |i|
      r += 1*pb**@sigma[i]
    end
    r
  end
end
### END: class EratosthenesLikeSieve
iod = STDIN
n,k = iod.gets.split
puts EratosthenesLikeSieve.new(n.to_i,k.to_f).ans
exit 0

0