結果

問題 No.713 素数の和
ユーザー GrayCoderGrayCoder
提出日時 2018-07-13 22:33:32
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 7,960 KB
最終ジャッジ日時 2023-07-30 09:46:38
合計ジャッジ時間 841 ms
ジャッジサーバーID
(参考情報)
judge13 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,856 KB
testcase_01 AC 16 ms
7,892 KB
testcase_02 AC 15 ms
7,884 KB
testcase_03 AC 16 ms
7,764 KB
testcase_04 AC 16 ms
7,764 KB
testcase_05 AC 16 ms
7,836 KB
testcase_06 AC 16 ms
7,760 KB
testcase_07 AC 15 ms
7,780 KB
testcase_08 AC 16 ms
7,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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