結果

問題 No.843 Triple Primes
ユーザー kozykozy
提出日時 2020-07-22 16:43:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 807 ms / 2,000 ms
コード長 568 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 29,928 KB
最終ジャッジ日時 2023-09-02 22:25:41
合計ジャッジ時間 17,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,892 KB
testcase_01 AC 656 ms
29,928 KB
testcase_02 AC 23 ms
8,612 KB
testcase_03 AC 18 ms
8,668 KB
testcase_04 AC 21 ms
8,756 KB
testcase_05 AC 18 ms
8,564 KB
testcase_06 AC 22 ms
8,900 KB
testcase_07 AC 482 ms
25,484 KB
testcase_08 AC 606 ms
27,432 KB
testcase_09 AC 674 ms
29,856 KB
testcase_10 AC 523 ms
26,520 KB
testcase_11 AC 590 ms
28,052 KB
testcase_12 AC 747 ms
29,364 KB
testcase_13 AC 694 ms
28,640 KB
testcase_14 AC 644 ms
28,596 KB
testcase_15 AC 504 ms
26,228 KB
testcase_16 AC 538 ms
26,204 KB
testcase_17 AC 16 ms
8,240 KB
testcase_18 AC 16 ms
8,288 KB
testcase_19 AC 16 ms
7,828 KB
testcase_20 AC 123 ms
14,188 KB
testcase_21 AC 66 ms
11,656 KB
testcase_22 AC 302 ms
20,284 KB
testcase_23 AC 320 ms
20,752 KB
testcase_24 AC 130 ms
14,444 KB
testcase_25 AC 96 ms
13,084 KB
testcase_26 AC 748 ms
29,812 KB
testcase_27 AC 32 ms
9,488 KB
testcase_28 AC 718 ms
29,084 KB
testcase_29 AC 136 ms
14,900 KB
testcase_30 AC 688 ms
29,476 KB
testcase_31 AC 44 ms
10,396 KB
testcase_32 AC 30 ms
9,364 KB
testcase_33 AC 165 ms
15,692 KB
testcase_34 AC 277 ms
19,212 KB
testcase_35 AC 807 ms
29,816 KB
testcase_36 AC 85 ms
12,376 KB
testcase_37 AC 492 ms
24,832 KB
testcase_38 AC 360 ms
22,216 KB
testcase_39 AC 692 ms
29,304 KB
testcase_40 AC 16 ms
8,200 KB
testcase_41 AC 16 ms
8,132 KB
testcase_42 AC 575 ms
26,752 KB
testcase_43 AC 625 ms
28,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def sieve_of_eratosthenes(n):
    candidate = list(range(2, n+1))
    prime = []
    limit = n**0.5 + 1
    while True:
        p = candidate[0] 
        if limit <= p:
            prime.extend(candidate)
            break
        prime.append(p)
        candidate = [i for i in candidate if i % p != 0]
    return prime
N=int(input())
if N==1:
  print(0)
  sys.exit()
if N==2:
  print(1)
  sys.exit()
prime = sieve_of_eratosthenes(N)
s=0
prime2=[i for i in prime if i<=800]
for i in range(len(prime2)):
  if (prime2[i]**2)-2 in prime:
    s+=1
print(s*2-1)
0