結果

問題 No.732 3PrimeCounting
ユーザー mkawa2mkawa2
提出日時 2020-11-12 11:14:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,169 ms / 3,000 ms
コード長 2,225 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 144,052 KB
最終ジャッジ日時 2023-09-30 01:11:58
合計ジャッジ時間 27,790 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
80,780 KB
testcase_01 AC 104 ms
80,700 KB
testcase_02 AC 108 ms
80,900 KB
testcase_03 AC 106 ms
80,784 KB
testcase_04 AC 104 ms
80,888 KB
testcase_05 AC 106 ms
80,808 KB
testcase_06 AC 106 ms
81,108 KB
testcase_07 AC 104 ms
81,028 KB
testcase_08 AC 108 ms
81,312 KB
testcase_09 AC 107 ms
81,308 KB
testcase_10 AC 109 ms
81,308 KB
testcase_11 AC 110 ms
81,200 KB
testcase_12 AC 109 ms
81,516 KB
testcase_13 AC 109 ms
81,340 KB
testcase_14 AC 108 ms
81,720 KB
testcase_15 AC 107 ms
81,436 KB
testcase_16 AC 108 ms
81,616 KB
testcase_17 AC 108 ms
81,664 KB
testcase_18 AC 109 ms
81,928 KB
testcase_19 AC 108 ms
81,608 KB
testcase_20 AC 128 ms
102,356 KB
testcase_21 AC 159 ms
137,008 KB
testcase_22 AC 159 ms
136,828 KB
testcase_23 AC 115 ms
88,872 KB
testcase_24 AC 116 ms
88,868 KB
testcase_25 AC 173 ms
143,808 KB
testcase_26 AC 163 ms
138,376 KB
testcase_27 AC 134 ms
110,948 KB
testcase_28 AC 134 ms
110,936 KB
testcase_29 AC 150 ms
130,532 KB
testcase_30 AC 151 ms
130,604 KB
testcase_31 AC 162 ms
138,544 KB
testcase_32 AC 165 ms
138,476 KB
testcase_33 AC 163 ms
138,372 KB
testcase_34 AC 163 ms
138,468 KB
testcase_35 AC 169 ms
138,832 KB
testcase_36 AC 161 ms
138,356 KB
testcase_37 AC 119 ms
95,736 KB
testcase_38 AC 119 ms
95,752 KB
testcase_39 AC 159 ms
138,040 KB
testcase_40 AC 160 ms
138,640 KB
testcase_41 AC 157 ms
138,884 KB
testcase_42 AC 159 ms
138,688 KB
testcase_43 AC 155 ms
130,568 KB
testcase_44 AC 151 ms
130,588 KB
testcase_45 AC 135 ms
116,876 KB
testcase_46 AC 136 ms
117,260 KB
testcase_47 AC 144 ms
126,712 KB
testcase_48 AC 173 ms
143,536 KB
testcase_49 AC 172 ms
143,524 KB
testcase_50 AC 158 ms
138,096 KB
testcase_51 AC 159 ms
138,856 KB
testcase_52 AC 136 ms
114,372 KB
testcase_53 AC 182 ms
135,356 KB
testcase_54 AC 506 ms
136,124 KB
testcase_55 AC 514 ms
136,180 KB
testcase_56 AC 529 ms
136,104 KB
testcase_57 AC 235 ms
135,616 KB
testcase_58 AC 234 ms
135,280 KB
testcase_59 AC 189 ms
135,308 KB
testcase_60 AC 276 ms
135,756 KB
testcase_61 AC 272 ms
135,680 KB
testcase_62 AC 643 ms
136,400 KB
testcase_63 AC 372 ms
135,996 KB
testcase_64 AC 303 ms
135,804 KB
testcase_65 AC 310 ms
135,860 KB
testcase_66 AC 113 ms
87,320 KB
testcase_67 AC 115 ms
87,632 KB
testcase_68 AC 586 ms
136,092 KB
testcase_69 AC 574 ms
136,240 KB
testcase_70 AC 515 ms
136,016 KB
testcase_71 AC 512 ms
136,132 KB
testcase_72 AC 341 ms
135,972 KB
testcase_73 AC 1,050 ms
136,592 KB
testcase_74 AC 893 ms
136,620 KB
testcase_75 AC 170 ms
144,052 KB
testcase_76 AC 540 ms
135,688 KB
testcase_77 AC 237 ms
135,660 KB
testcase_78 AC 739 ms
136,296 KB
testcase_79 AC 568 ms
136,252 KB
testcase_80 AC 676 ms
136,192 KB
testcase_81 AC 519 ms
136,196 KB
testcase_82 AC 128 ms
107,592 KB
testcase_83 AC 233 ms
135,460 KB
testcase_84 AC 239 ms
135,680 KB
testcase_85 AC 483 ms
135,932 KB
testcase_86 AC 696 ms
136,112 KB
testcase_87 AC 1,169 ms
136,696 KB
testcase_88 AC 1,169 ms
136,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter
from itertools import *
from bisect import *
from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MI1(): return map(int1, sys.stdin.buffer.readline().split())
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
def inval(ni, nj, h, w):
    if ni < 0 or ni >= h or nj < 0 or nj >= w: return True
    return False
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
inf = 10**16

class Sieve:
    def __init__(self, n):
        self.plist = [2]  # n以下の素数のリスト
        min_prime_factor = [2, 0]*(n//2+5)
        for x in range(3, n+1, 2):
            if min_prime_factor[x] == 0:
                min_prime_factor[x] = x
                self.plist.append(x)
                if x**2 > n: continue
                for y in range(x**2, n+5, 2*x):
                    if min_prime_factor[y] == 0:
                        min_prime_factor[y] = x
        self.min_prime_factor = min_prime_factor

    def isprime(self, x):
        return self.min_prime_factor[x] == x

    # これが素因数分解(prime factorization)
    def pfct(self, x):
        pp, ee = [], []
        while x > 1:
            mpf = self.min_prime_factor[x]
            if pp and mpf == pp[-1]:
                ee[-1] += 1
            else:
                pp.append(mpf)
                ee.append(1)
            x //= mpf
        return [(p, e) for p, e in zip(pp, ee)]

n = II()
sv = Sieve(300000)
pp = sv.plist
cnt = [0]*(2*n+1)
ans = 0
for i, c in enumerate(pp[2:], 2):
    if c > n: break
    p1 = pp[i-1]
    for p2 in pp[:i-1]:
        cnt[p1+p2] += 1
    for s in pp[i+1:]:
        if s-c < 4: continue
        if s-c > 2*n: break
        ans += cnt[s-c]

print(ans)
0