結果

問題 No.144 エラトステネスのざる
ユーザー hytkxdhytkxd
提出日時 2023-09-01 16:39:37
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,288 ms / 2,000 ms
コード長 465 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 11,292 KB
実行使用メモリ 23,524 KB
最終ジャッジ日時 2023-09-01 16:39:51
合計ジャッジ時間 11,034 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,268 KB
testcase_01 AC 79 ms
15,160 KB
testcase_02 AC 77 ms
15,480 KB
testcase_03 AC 81 ms
15,152 KB
testcase_04 AC 79 ms
15,428 KB
testcase_05 AC 85 ms
15,472 KB
testcase_06 AC 77 ms
15,604 KB
testcase_07 AC 75 ms
15,568 KB
testcase_08 AC 87 ms
15,720 KB
testcase_09 AC 74 ms
15,632 KB
testcase_10 AC 76 ms
15,524 KB
testcase_11 AC 76 ms
15,664 KB
testcase_12 AC 77 ms
15,404 KB
testcase_13 AC 1,164 ms
23,252 KB
testcase_14 AC 1,288 ms
23,476 KB
testcase_15 AC 1,185 ms
23,356 KB
testcase_16 AC 1,146 ms
23,520 KB
testcase_17 AC 1,110 ms
23,520 KB
testcase_18 AC 1,243 ms
23,524 KB
testcase_19 AC 1,236 ms
23,028 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/local/bin/ruby
class EratosthenesLikeSieve
  def initialize(*arg)
    @n,@k = arg
  end
  def ans
    r = 0
    sigma = Array.new(@n+1,0)
    pb = 1-@k
    i=2
    while i <= @n
      last = @n/i
      j=2
      while j<=last
        sigma[j*i]+=1
        j+=1
      end
      r += pb**sigma[i]
      i+=1
    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