結果

問題 No.713 素数の和
ユーザー hiragnhiragn
提出日時 2022-11-10 19:51:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 464 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,556 KB
実行使用メモリ 7,940 KB
最終ジャッジ日時 2023-10-01 03:43:35
合計ジャッジ時間 992 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,824 KB
testcase_01 AC 17 ms
7,816 KB
testcase_02 AC 16 ms
7,768 KB
testcase_03 AC 16 ms
7,752 KB
testcase_04 AC 16 ms
7,784 KB
testcase_05 AC 14 ms
7,940 KB
testcase_06 AC 15 ms
7,816 KB
testcase_07 AC 14 ms
7,928 KB
testcase_08 AC 14 ms
7,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve_of_eratosthenes(n):
    sieve = [True for _ in range(n + 1)]
    sieve[0:1] = [False, False]

    for i in range(2, n + 1):
        if sieve[i]:
            for j in range(2 * i, n + 1, i):
                sieve[j] = False

    primes = []
    for i in range(2, n + 1):
        if sieve[i]:
            primes.append(i)
    return primes


def main():
    n = int(input())
    print(sum(sieve_of_eratosthenes(n)))


if __name__ == "__main__":
    main()
0