結果

問題 No.713 素数の和
ユーザー simamumusimamumu
提出日時 2018-07-13 22:24:07
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 690 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 9,512 KB
最終ジャッジ日時 2023-07-30 09:43:43
合計ジャッジ時間 1,228 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
9,504 KB
testcase_01 AC 28 ms
9,368 KB
testcase_02 AC 27 ms
9,440 KB
testcase_03 AC 28 ms
9,332 KB
testcase_04 AC 28 ms
9,300 KB
testcase_05 AC 28 ms
9,304 KB
testcase_06 AC 28 ms
9,332 KB
testcase_07 AC 28 ms
9,336 KB
testcase_08 AC 28 ms
9,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict 
import sys,heapq,bisect,math,itertools,string

mod = 10**9 + 7


def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True
	
N = int(input())
ans = 0

for i in range(N+1):
	if is_prime(i):
		ans += i

print(ans)
0