結果

問題 No.843 Triple Primes
ユーザー _KingdomOfMoray_KingdomOfMoray
提出日時 2020-01-10 09:12:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 505 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 22,144 KB
最終ジャッジ日時 2024-05-03 01:38:51
合計ジャッジ時間 11,890 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
11,008 KB
testcase_01 AC 505 ms
22,016 KB
testcase_02 AC 33 ms
11,136 KB
testcase_03 AC 32 ms
11,008 KB
testcase_04 AC 33 ms
11,008 KB
testcase_05 AC 32 ms
10,880 KB
testcase_06 AC 35 ms
11,008 KB
testcase_07 AC 359 ms
19,840 KB
testcase_08 AC 409 ms
20,736 KB
testcase_09 AC 489 ms
22,144 KB
testcase_10 AC 381 ms
20,224 KB
testcase_11 AC 440 ms
21,248 KB
testcase_12 AC 478 ms
21,888 KB
testcase_13 AC 456 ms
21,376 KB
testcase_14 AC 459 ms
21,376 KB
testcase_15 AC 369 ms
20,096 KB
testcase_16 AC 390 ms
20,224 KB
testcase_17 AC 30 ms
10,880 KB
testcase_18 AC 29 ms
10,752 KB
testcase_19 AC 30 ms
11,008 KB
testcase_20 AC 105 ms
13,952 KB
testcase_21 AC 64 ms
12,544 KB
testcase_22 AC 228 ms
17,152 KB
testcase_23 AC 244 ms
17,280 KB
testcase_24 AC 112 ms
14,080 KB
testcase_25 AC 88 ms
13,312 KB
testcase_26 AC 483 ms
21,888 KB
testcase_27 AC 42 ms
11,392 KB
testcase_28 AC 450 ms
21,632 KB
testcase_29 AC 119 ms
14,336 KB
testcase_30 AC 453 ms
21,760 KB
testcase_31 AC 49 ms
11,904 KB
testcase_32 AC 39 ms
11,392 KB
testcase_33 AC 132 ms
14,720 KB
testcase_34 AC 208 ms
16,512 KB
testcase_35 AC 481 ms
22,016 KB
testcase_36 AC 79 ms
13,056 KB
testcase_37 AC 347 ms
19,456 KB
testcase_38 AC 278 ms
18,176 KB
testcase_39 AC 454 ms
21,632 KB
testcase_40 AC 31 ms
10,880 KB
testcase_41 AC 31 ms
10,752 KB
testcase_42 AC 389 ms
20,352 KB
testcase_43 AC 439 ms
21,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def get_list_primes(n):
    if n == 1:
        return []
    if n == 2:
        return [2]
    
    prime_list = [2]
    num_list = [e + 1 for e in range(2, n, 2)]
    limit = int(n ** 0.5)

    while True:
        leader = num_list[0]
        if limit < leader:
            return prime_list + num_list
        prime_list.append(leader)
        num_list = [e for e in num_list if e % leader != 0]

def judge_prime(n):
    res = None
    count = 0
    
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            count += 1
            if n // i != i:
                count += 1
                
    if count > 2:
        res = 0
    else:
        res = 1
        
    return res
        
n = int(input())

prime_list = get_list_primes(n)
len_list = len(prime_list)
res = 0

for i in range(len_list):
    target = (prime_list[i] + 2) ** 0.5
    if math.ceil(target) != math.floor(target):
        continue
    if judge_prime(int(target)) == 1:
        if prime_list[i] == target:
            res += 1
        else:
            res += 2
        
print(res)
0