結果

問題 No.843 Triple Primes
ユーザー hedwig100hedwig100
提出日時 2020-04-17 13:05:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 640 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 32,384 KB
最終ジャッジ日時 2024-04-14 12:36:04
合計ジャッジ時間 14,467 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 640 ms
32,256 KB
testcase_02 AC 34 ms
10,880 KB
testcase_03 AC 32 ms
11,136 KB
testcase_04 AC 34 ms
11,264 KB
testcase_05 AC 32 ms
11,008 KB
testcase_06 AC 35 ms
11,136 KB
testcase_07 AC 449 ms
28,160 KB
testcase_08 AC 520 ms
29,696 KB
testcase_09 AC 621 ms
32,384 KB
testcase_10 AC 472 ms
28,672 KB
testcase_11 AC 549 ms
30,720 KB
testcase_12 AC 600 ms
31,872 KB
testcase_13 AC 591 ms
31,104 KB
testcase_14 AC 609 ms
31,104 KB
testcase_15 AC 472 ms
28,416 KB
testcase_16 AC 465 ms
28,672 KB
testcase_17 AC 30 ms
10,624 KB
testcase_18 AC 30 ms
10,752 KB
testcase_19 AC 30 ms
10,624 KB
testcase_20 AC 121 ms
16,512 KB
testcase_21 AC 72 ms
14,208 KB
testcase_22 AC 273 ms
22,656 KB
testcase_23 AC 277 ms
23,168 KB
testcase_24 AC 126 ms
16,896 KB
testcase_25 AC 98 ms
15,488 KB
testcase_26 AC 595 ms
32,128 KB
testcase_27 AC 43 ms
11,904 KB
testcase_28 AC 575 ms
31,360 KB
testcase_29 AC 137 ms
17,408 KB
testcase_30 AC 580 ms
32,000 KB
testcase_31 AC 53 ms
12,928 KB
testcase_32 AC 41 ms
11,904 KB
testcase_33 AC 151 ms
18,048 KB
testcase_34 AC 250 ms
21,760 KB
testcase_35 AC 616 ms
32,256 KB
testcase_36 AC 87 ms
14,848 KB
testcase_37 AC 422 ms
27,392 KB
testcase_38 AC 332 ms
24,832 KB
testcase_39 AC 586 ms
31,488 KB
testcase_40 AC 30 ms
10,752 KB
testcase_41 AC 30 ms
10,624 KB
testcase_42 AC 476 ms
29,184 KB
testcase_43 AC 534 ms
30,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
INF = 10 ** 20
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
from collections import defaultdict
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def sieve(n):
    prime = []
    limit = n ** 0.5
    data = [i + 1 for i in range(1,n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e%p != 0]

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,n):
        if i * i > n:
            break
        if n%i == 0:
            return  False
    return True

def main():
    n = int(input())
    if n == 1:
        print(0)
        return

    primes = sieve(n)
    ans = 1
    for p in primes:
        if p == 2:
            continue
        if p * p - 2 <= n and is_prime(p * p - 2):
            #print(p * p - 2,2,p)
            ans += 2

    print(ans)

if __name__ =='__main__':
    main()  
0