結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,624 KB
testcase_01 AC 588 ms
32,384 KB
testcase_02 AC 33 ms
10,880 KB
testcase_03 AC 33 ms
11,008 KB
testcase_04 AC 34 ms
11,008 KB
testcase_05 AC 32 ms
11,008 KB
testcase_06 AC 34 ms
11,392 KB
testcase_07 AC 429 ms
28,032 KB
testcase_08 AC 489 ms
29,696 KB
testcase_09 AC 572 ms
32,256 KB
testcase_10 AC 452 ms
28,800 KB
testcase_11 AC 517 ms
30,592 KB
testcase_12 AC 564 ms
31,744 KB
testcase_13 AC 537 ms
31,232 KB
testcase_14 AC 543 ms
31,232 KB
testcase_15 AC 433 ms
28,416 KB
testcase_16 AC 450 ms
28,672 KB
testcase_17 RE -
testcase_18 AC 30 ms
10,624 KB
testcase_19 AC 30 ms
10,752 KB
testcase_20 AC 120 ms
16,512 KB
testcase_21 AC 72 ms
14,080 KB
testcase_22 AC 271 ms
22,656 KB
testcase_23 AC 279 ms
23,296 KB
testcase_24 AC 127 ms
16,896 KB
testcase_25 AC 98 ms
15,360 KB
testcase_26 AC 581 ms
32,128 KB
testcase_27 AC 43 ms
12,032 KB
testcase_28 AC 547 ms
31,360 KB
testcase_29 AC 136 ms
17,408 KB
testcase_30 AC 560 ms
31,872 KB
testcase_31 AC 53 ms
12,672 KB
testcase_32 AC 42 ms
11,904 KB
testcase_33 AC 151 ms
18,048 KB
testcase_34 AC 243 ms
21,760 KB
testcase_35 AC 558 ms
32,256 KB
testcase_36 AC 89 ms
14,848 KB
testcase_37 AC 402 ms
27,392 KB
testcase_38 AC 320 ms
24,704 KB
testcase_39 AC 557 ms
31,488 KB
testcase_40 AC 30 ms
10,624 KB
testcase_41 RE -
testcase_42 AC 464 ms
29,184 KB
testcase_43 AC 516 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())
    primes = sieve(n)

    if n == 1:
        print(0)
        return
    
    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