結果

問題 No.843 Triple Primes
ユーザー kekurekekure
提出日時 2019-07-06 11:07:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 917 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 74,708 KB
最終ジャッジ日時 2023-10-19 18:00:01
合計ジャッジ時間 5,825 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,552 KB
testcase_01 AC 142 ms
74,708 KB
testcase_02 AC 47 ms
62,012 KB
testcase_03 AC 47 ms
62,012 KB
testcase_04 AC 48 ms
62,152 KB
testcase_05 AC 46 ms
62,012 KB
testcase_06 AC 50 ms
64,412 KB
testcase_07 AC 120 ms
71,996 KB
testcase_08 AC 129 ms
74,348 KB
testcase_09 AC 143 ms
74,704 KB
testcase_10 AC 124 ms
74,052 KB
testcase_11 AC 134 ms
74,360 KB
testcase_12 AC 141 ms
74,376 KB
testcase_13 AC 137 ms
74,368 KB
testcase_14 AC 137 ms
74,372 KB
testcase_15 AC 122 ms
72,000 KB
testcase_16 AC 123 ms
74,052 KB
testcase_17 AC 37 ms
53,552 KB
testcase_18 AC 37 ms
53,552 KB
testcase_19 AC 36 ms
53,552 KB
testcase_20 AC 69 ms
66,476 KB
testcase_21 AC 60 ms
66,476 KB
testcase_22 AC 95 ms
71,240 KB
testcase_23 AC 97 ms
71,248 KB
testcase_24 AC 69 ms
66,476 KB
testcase_25 AC 64 ms
66,476 KB
testcase_26 AC 142 ms
74,704 KB
testcase_27 AC 54 ms
64,428 KB
testcase_28 AC 137 ms
74,372 KB
testcase_29 AC 71 ms
68,524 KB
testcase_30 AC 140 ms
74,376 KB
testcase_31 AC 55 ms
64,428 KB
testcase_32 AC 53 ms
64,428 KB
testcase_33 AC 74 ms
68,524 KB
testcase_34 AC 90 ms
69,000 KB
testcase_35 AC 142 ms
74,704 KB
testcase_36 AC 63 ms
66,476 KB
testcase_37 AC 118 ms
71,984 KB
testcase_38 AC 104 ms
71,472 KB
testcase_39 AC 139 ms
74,376 KB
testcase_40 AC 37 ms
53,552 KB
testcase_41 AC 37 ms
53,552 KB
testcase_42 AC 127 ms
74,056 KB
testcase_43 AC 133 ms
74,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def makeprime(k) :
    prime = [2,3,5,7,11]

    for i in range(13, k + 1, 2) :
        if (i % 3 == 0 or i % 5 == 0 or i % 7 == 0 or i % 11 == 0) :
            continue
        limit = int(math.sqrt(i)) + 1
        isprime = False
        for x in prime :
            if (x > limit) :
                isprime = True
                break
            if (i % x == 0) :
                break
        if (isprime) :
            prime.append(i)
    
    return prime

k = int(input())
prime = makeprime(k)

i_r = 1
i_q = 3
cnt = 0

last_prime = prime[-1]
limit_r = math.sqrt(2 + k)

while (prime[i_r] <= limit_r) :
    R = prime[i_r] ** 2
    while (True) :
        Q = 2 + prime[i_q]
        if (R == Q) :
            cnt += 1
            break
        elif (Q > R or prime[i_q] == last_prime) :
            break
        i_q += 1
    i_r += 1

print(cnt * 2 + 1 if k > 1 else 0)
            



    
0