結果

問題 No.843 Triple Primes
ユーザー O2MTO2MT
提出日時 2020-12-08 12:08:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 575 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 70,212 KB
最終ジャッジ日時 2023-10-17 17:08:35
合計ジャッジ時間 15,687 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
65,828 KB
testcase_01 AC 575 ms
69,676 KB
testcase_02 AC 78 ms
69,620 KB
testcase_03 AC 75 ms
69,620 KB
testcase_04 AC 79 ms
69,628 KB
testcase_05 AC 110 ms
69,616 KB
testcase_06 AC 80 ms
70,128 KB
testcase_07 AC 469 ms
69,464 KB
testcase_08 AC 504 ms
69,732 KB
testcase_09 AC 568 ms
69,568 KB
testcase_10 AC 484 ms
69,676 KB
testcase_11 AC 533 ms
70,040 KB
testcase_12 AC 556 ms
69,472 KB
testcase_13 AC 545 ms
69,684 KB
testcase_14 AC 553 ms
68,824 KB
testcase_15 AC 473 ms
69,700 KB
testcase_16 AC 484 ms
69,704 KB
testcase_17 AC 65 ms
65,840 KB
testcase_18 AC 65 ms
65,840 KB
testcase_19 AC 64 ms
65,900 KB
testcase_20 AC 196 ms
69,676 KB
testcase_21 AC 137 ms
69,672 KB
testcase_22 AC 336 ms
69,696 KB
testcase_23 AC 349 ms
69,272 KB
testcase_24 AC 206 ms
68,832 KB
testcase_25 AC 175 ms
70,212 KB
testcase_26 AC 570 ms
70,212 KB
testcase_27 AC 97 ms
70,212 KB
testcase_28 AC 531 ms
70,212 KB
testcase_29 AC 214 ms
70,212 KB
testcase_30 AC 560 ms
70,212 KB
testcase_31 AC 114 ms
70,212 KB
testcase_32 AC 94 ms
70,212 KB
testcase_33 AC 229 ms
70,212 KB
testcase_34 AC 316 ms
70,212 KB
testcase_35 AC 573 ms
70,212 KB
testcase_36 AC 160 ms
70,212 KB
testcase_37 AC 453 ms
70,212 KB
testcase_38 AC 388 ms
70,212 KB
testcase_39 AC 551 ms
70,212 KB
testcase_40 AC 64 ms
67,340 KB
testcase_41 AC 65 ms
67,340 KB
testcase_42 AC 494 ms
70,212 KB
testcase_43 AC 532 ms
70,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    l = [False]*(n+1)
    for i in range(n+1):
        if is_prime[i]:
            l[i] = True

    return l

N = int(input())
R = int(sqrt(10**6))
arr = primes(5*(10**5)+1)
count = 0
for r in range(1,min(N,R)+1):
    if arr[r]:
        for p in range(1,N+1):
            q = r**2-p
            if q > N or q < 1:
                continue
            if arr[p] and arr[q]:
                count += 1

print(count)
0