結果

問題 No.713 素数の和
ユーザー mesame3993mesame3993
提出日時 2021-11-19 16:04:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 368 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 87,332 KB
実行使用メモリ 76,220 KB
最終ジャッジ日時 2023-08-29 23:49:48
合計ジャッジ時間 2,069 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,220 KB
testcase_01 AC 71 ms
71,512 KB
testcase_02 AC 72 ms
71,540 KB
testcase_03 AC 73 ms
75,984 KB
testcase_04 AC 74 ms
75,928 KB
testcase_05 AC 72 ms
71,652 KB
testcase_06 AC 71 ms
71,820 KB
testcase_07 AC 84 ms
71,516 KB
testcase_08 AC 72 ms
71,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def eratosthenes(n):
  if n < 2:
    return [0]
  if n == 2:
    return [2]
  prime = [2]
  limit = int(n**0.5)+1
  data = [i for i in range(3, n+1, 2)]
  while True:
    p = data[0]
    if limit <= p:
      return prime + data
    prime.append(p)
    data = [e for e in data if e%p!=0]

def main():
  n = int(input())
  arr = eratosthenes(n)
  print(sum(arr))

main()
0