結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,192 KB
testcase_01 AC 80 ms
15,352 KB
testcase_02 AC 82 ms
15,296 KB
testcase_03 AC 81 ms
15,196 KB
testcase_04 AC 80 ms
15,376 KB
testcase_05 AC 81 ms
15,408 KB
testcase_06 AC 86 ms
15,256 KB
testcase_07 AC 84 ms
15,404 KB
testcase_08 AC 86 ms
15,588 KB
testcase_09 AC 85 ms
15,408 KB
testcase_10 AC 84 ms
15,408 KB
testcase_11 AC 83 ms
15,464 KB
testcase_12 AC 83 ms
15,412 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)
  end
  def ans
    r = 0
    pb = 1-@k
    (2..@n).each do |i|
      last = @n/i
      (2..last).each do |j|
        @sigma[j*i]+=1
      end
      r += 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