結果

問題 No.713 素数の和
ユーザー yuppe19 😺yuppe19 😺
提出日時 2018-07-25 21:45:36
言語 Python2
(2.7.18)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 464 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 6,708 KB
実行使用メモリ 6,384 KB
最終ジャッジ日時 2023-09-09 10:44:13
合計ジャッジ時間 1,101 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,356 KB
testcase_01 AC 10 ms
5,876 KB
testcase_02 AC 11 ms
6,248 KB
testcase_03 AC 12 ms
6,160 KB
testcase_04 AC 11 ms
6,384 KB
testcase_05 AC 11 ms
6,308 KB
testcase_06 AC 11 ms
6,300 KB
testcase_07 AC 11 ms
6,168 KB
testcase_08 AC 11 ms
6,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
def sum_of_primes(n):
    r = int(n ** .5)
    V = [n//i for i in xrange(1, r+1)]
    V += reversed(xrange(V[-1]))
    S = {i: i*(i+1)//2-1 for i in V}
    for p in xrange(2, r+1):
        if S[p] > S[p-1]:
            p2 = p * p
            for v in V:
                if v < p2:
                    break
                S[v] -= p * (S[v//p] - S[p-1])
    return S[n]

n = int(raw_input())
print sum_of_primes(n)
0