結果

問題 No.843 Triple Primes
ユーザー mkawa2mkawa2
提出日時 2021-03-17 02:17:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 1,071 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 16,768 KB
最終ジャッジ日時 2024-04-26 10:49:26
合計ジャッジ時間 11,180 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 213 ms
16,640 KB
testcase_01 AC 212 ms
16,640 KB
testcase_02 AC 222 ms
16,640 KB
testcase_03 AC 216 ms
16,640 KB
testcase_04 AC 208 ms
16,512 KB
testcase_05 AC 230 ms
16,640 KB
testcase_06 AC 222 ms
16,768 KB
testcase_07 AC 215 ms
16,512 KB
testcase_08 AC 218 ms
16,640 KB
testcase_09 AC 214 ms
16,640 KB
testcase_10 AC 213 ms
16,512 KB
testcase_11 AC 212 ms
16,768 KB
testcase_12 AC 221 ms
16,512 KB
testcase_13 AC 224 ms
16,640 KB
testcase_14 AC 213 ms
16,640 KB
testcase_15 AC 224 ms
16,512 KB
testcase_16 AC 214 ms
16,640 KB
testcase_17 AC 224 ms
16,384 KB
testcase_18 AC 217 ms
16,640 KB
testcase_19 AC 211 ms
16,640 KB
testcase_20 AC 214 ms
16,640 KB
testcase_21 AC 217 ms
16,512 KB
testcase_22 AC 219 ms
16,512 KB
testcase_23 AC 217 ms
16,512 KB
testcase_24 AC 208 ms
16,512 KB
testcase_25 AC 208 ms
16,640 KB
testcase_26 AC 225 ms
16,732 KB
testcase_27 AC 218 ms
16,512 KB
testcase_28 AC 214 ms
16,512 KB
testcase_29 AC 207 ms
16,512 KB
testcase_30 AC 211 ms
16,512 KB
testcase_31 AC 212 ms
16,620 KB
testcase_32 AC 212 ms
16,640 KB
testcase_33 AC 222 ms
16,684 KB
testcase_34 AC 217 ms
16,640 KB
testcase_35 AC 212 ms
16,512 KB
testcase_36 AC 218 ms
16,512 KB
testcase_37 AC 211 ms
16,512 KB
testcase_38 AC 213 ms
16,640 KB
testcase_39 AC 226 ms
16,680 KB
testcase_40 AC 215 ms
16,640 KB
testcase_41 AC 211 ms
16,364 KB
testcase_42 AC 214 ms
16,684 KB
testcase_43 AC 207 ms
16,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
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()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 998244353
# md = 10**9+7

mx = 500001

isprime = [True]*mx
isprime[0] = isprime[1] = False
pp = []
for a in range(2, mx):
    if isprime[a]:
        pp.append(a)
        for b in range(a**2, mx, a):
            isprime[b] = False

n = II()
if n == 1:
    print(0)
    exit()

ans = 1
for r in pp[1:]:
    p = r**2-2
    if r > n or p > n: break
    if isprime[p]:
        ans += 2

print(ans)
0