結果

問題 No.843 Triple Primes
ユーザー kekurekekure
提出日時 2019-07-06 11:18:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 11,912 KB
最終ジャッジ日時 2023-10-19 18:00:55
合計ジャッジ時間 10,238 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,200 KB
testcase_01 AC 397 ms
11,912 KB
testcase_02 AC 33 ms
10,220 KB
testcase_03 AC 33 ms
10,216 KB
testcase_04 AC 34 ms
10,240 KB
testcase_05 AC 32 ms
10,216 KB
testcase_06 AC 34 ms
10,244 KB
testcase_07 AC 307 ms
11,612 KB
testcase_08 AC 340 ms
11,724 KB
testcase_09 AC 391 ms
11,900 KB
testcase_10 AC 319 ms
11,660 KB
testcase_11 AC 358 ms
11,784 KB
testcase_12 AC 385 ms
11,868 KB
testcase_13 AC 375 ms
11,828 KB
testcase_14 AC 373 ms
11,832 KB
testcase_15 AC 315 ms
11,632 KB
testcase_16 AC 318 ms
11,652 KB
testcase_17 AC 31 ms
10,200 KB
testcase_18 AC 31 ms
10,200 KB
testcase_19 AC 30 ms
10,200 KB
testcase_20 AC 101 ms
10,684 KB
testcase_21 AC 65 ms
10,476 KB
testcase_22 AC 203 ms
11,228 KB
testcase_23 AC 213 ms
11,260 KB
testcase_24 AC 105 ms
10,708 KB
testcase_25 AC 84 ms
10,596 KB
testcase_26 AC 393 ms
11,896 KB
testcase_27 AC 41 ms
10,316 KB
testcase_28 AC 378 ms
11,840 KB
testcase_29 AC 113 ms
10,740 KB
testcase_30 AC 385 ms
11,876 KB
testcase_31 AC 49 ms
10,372 KB
testcase_32 AC 40 ms
10,300 KB
testcase_33 AC 122 ms
10,880 KB
testcase_34 AC 185 ms
11,156 KB
testcase_35 AC 395 ms
11,900 KB
testcase_36 AC 78 ms
10,556 KB
testcase_37 AC 292 ms
11,564 KB
testcase_38 AC 240 ms
11,376 KB
testcase_39 AC 379 ms
11,856 KB
testcase_40 AC 30 ms
10,200 KB
testcase_41 AC 30 ms
10,200 KB
testcase_42 AC 328 ms
11,688 KB
testcase_43 AC 360 ms
11,784 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