結果

問題 No.106 素数が嫌い!2
ユーザー tshigtshig
提出日時 2016-08-09 12:35:35
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,308 ms / 5,000 ms
コード長 448 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 36,736 KB
最終ジャッジ日時 2024-04-24 22:52:59
合計ジャッジ時間 9,922 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
12,160 KB
testcase_01 AC 100 ms
12,160 KB
testcase_02 AC 93 ms
12,160 KB
testcase_03 AC 95 ms
12,032 KB
testcase_04 AC 709 ms
27,136 KB
testcase_05 AC 1,299 ms
28,544 KB
testcase_06 AC 1,300 ms
27,648 KB
testcase_07 AC 1,306 ms
27,904 KB
testcase_08 AC 161 ms
13,952 KB
testcase_09 AC 155 ms
13,056 KB
testcase_10 AC 1,308 ms
27,776 KB
testcase_11 AC 590 ms
19,072 KB
testcase_12 AC 1,287 ms
36,736 KB
testcase_13 AC 95 ms
12,160 KB
testcase_14 AC 91 ms
12,160 KB
testcase_15 AC 95 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Calc0106
  def initialize(args)
    args = args.map { |l| l.chomp.split(/\s+/) }
    @n, @k = args.shift.map(&:to_i)
  end

  def run
    return @n - 1 if @k == 1

    @memo = Array.new(@n + 1) { 0 }
    (2..(@n / 2)).each do |m|
      if @memo[m] == 0
        m.step(@n, m) do |i|
          @memo[i] += 1
        end
      end
    end
    @memo.select { |v| v >= @k }.size
  end
end

puts Calc0106.new(STDIN.readlines).run if __FILE__ == $0
0