結果

問題 No.458 異なる素数の和
ユーザー efunyoefunyo
提出日時 2020-04-06 21:08:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 1,187 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 86,672 KB
実行使用メモリ 77,904 KB
最終ジャッジ日時 2023-09-21 07:04:33
合計ジャッジ時間 6,697 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
76,796 KB
testcase_01 AC 183 ms
77,524 KB
testcase_02 AC 204 ms
77,800 KB
testcase_03 AC 124 ms
77,328 KB
testcase_04 AC 129 ms
77,884 KB
testcase_05 AC 324 ms
77,604 KB
testcase_06 AC 198 ms
77,536 KB
testcase_07 AC 103 ms
76,792 KB
testcase_08 AC 324 ms
77,856 KB
testcase_09 AC 109 ms
77,296 KB
testcase_10 AC 94 ms
71,444 KB
testcase_11 AC 365 ms
77,904 KB
testcase_12 AC 92 ms
72,076 KB
testcase_13 AC 93 ms
72,060 KB
testcase_14 AC 96 ms
71,964 KB
testcase_15 AC 93 ms
71,896 KB
testcase_16 AC 118 ms
77,816 KB
testcase_17 AC 92 ms
72,124 KB
testcase_18 AC 94 ms
72,184 KB
testcase_19 AC 92 ms
72,136 KB
testcase_20 AC 99 ms
76,808 KB
testcase_21 AC 94 ms
71,856 KB
testcase_22 AC 93 ms
72,088 KB
testcase_23 AC 99 ms
76,980 KB
testcase_24 AC 99 ms
76,764 KB
testcase_25 AC 94 ms
71,996 KB
testcase_26 AC 96 ms
72,140 KB
testcase_27 AC 192 ms
77,860 KB
testcase_28 AC 360 ms
77,860 KB
testcase_29 AC 110 ms
77,820 KB
testcase_30 AC 159 ms
77,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

'''
https://yukicoder.me/problems/931
'''

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    def primecheck(n):
        #0~nまで素数判定
        p = [True] * (n + 1)
        p[0] = False
        p[1] = False
        for i in range(2, int(n ** 0.5) + 1):
            if p[i]:
                for j in range(i * i, n + 1, i):
                    p[j] = False
        return p
    
    p = primecheck(n)
    l = []
    for i, x in enumerate(p):
        if x:
            l.append(i)
    
    dp = [-1]*(n+1)
    dp[0] = 0
    for i in l:
        for j in range(n, i-1, -1):
            if dp[j-i] >= 0:
                dp[j] = max(dp[j-i]+1, dp[j])
    print(dp[-1])
            
if __name__ == '__main__':
    main()
0