結果

問題 No.713 素数の和
コンテスト
ユーザー GrayCoder
提出日時 2018-07-13 22:33:32
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 582 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 547 ms
コンパイル使用メモリ 20,956 KB
実行使用メモリ 15,356 KB
最終ジャッジ日時 2026-04-25 08:07:38
合計ジャッジ時間 2,074 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
write = stdout.write

def main():
    N = int(input())

    if N == 1:
        print(0)
        return

    lst = erastosthenes(N)
    prime_list = [2] + [i for i in range(3, N + 1, 2) if lst[i]]
    print(sum(prime_list))

def erastosthenes(n):
    prime = [0, 1] * ((n + 1) // 2)
    if not n % 2:
        prime += [0]
    prime[1], prime[2] = 0, 1

    sqrt = n ** 0.5
    i = 3
    while i <= sqrt:
        for j in range(i ** 2, n + 1, i):
            prime[j] = 0
        i += 2
    return prime

main()
0