結果

問題 No.713 素数の和
ユーザー object1234object1234
提出日時 2019-01-19 19:18:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 388 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 11,292 KB
実行使用メモリ 15,288 KB
最終ジャッジ日時 2023-09-25 08:21:07
合計ジャッジ時間 1,662 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
15,120 KB
testcase_01 AC 83 ms
15,084 KB
testcase_02 AC 86 ms
15,276 KB
testcase_03 AC 86 ms
15,288 KB
testcase_04 AC 89 ms
15,140 KB
testcase_05 AC 83 ms
15,228 KB
testcase_06 AC 86 ms
15,044 KB
testcase_07 AC 81 ms
15,116 KB
testcase_08 AC 83 ms
15,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def prime?(n)
    return false if n == 0 or n == 1
    res = true
    n.times do |i|
        next if i == 0 or i == 1
        if n % i == 0
            res = false
            break
        end
    end
    res
end

max = gets.chomp.to_i
res = []
(0..max).each do |i|
    res << i if prime?(i)
end

result = res.inject { |sum, k| sum + k}
if result.nil?
    puts 0
else
    puts result
end
0