結果

問題 No.843 Triple Primes
ユーザー kohei2019kohei2019
提出日時 2022-04-23 00:07:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 86,412 KB
最終ジャッジ日時 2023-09-06 11:05:35
合計ジャッジ時間 8,080 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,728 KB
testcase_01 AC 270 ms
85,924 KB
testcase_02 AC 74 ms
76,460 KB
testcase_03 AC 70 ms
76,516 KB
testcase_04 AC 76 ms
76,472 KB
testcase_05 AC 71 ms
76,508 KB
testcase_06 AC 72 ms
76,520 KB
testcase_07 AC 173 ms
83,692 KB
testcase_08 AC 195 ms
84,736 KB
testcase_09 AC 235 ms
86,280 KB
testcase_10 AC 167 ms
84,236 KB
testcase_11 AC 205 ms
85,544 KB
testcase_12 AC 224 ms
86,256 KB
testcase_13 AC 215 ms
85,396 KB
testcase_14 AC 209 ms
85,432 KB
testcase_15 AC 169 ms
84,028 KB
testcase_16 AC 195 ms
84,164 KB
testcase_17 AC 63 ms
70,964 KB
testcase_18 AC 68 ms
71,680 KB
testcase_19 AC 67 ms
71,464 KB
testcase_20 AC 87 ms
78,164 KB
testcase_21 AC 81 ms
76,840 KB
testcase_22 AC 114 ms
81,420 KB
testcase_23 AC 119 ms
81,968 KB
testcase_24 AC 82 ms
78,344 KB
testcase_25 AC 94 ms
77,552 KB
testcase_26 AC 241 ms
86,360 KB
testcase_27 AC 74 ms
76,740 KB
testcase_28 AC 210 ms
85,364 KB
testcase_29 AC 91 ms
78,824 KB
testcase_30 AC 231 ms
86,132 KB
testcase_31 AC 78 ms
76,892 KB
testcase_32 AC 74 ms
76,452 KB
testcase_33 AC 97 ms
79,096 KB
testcase_34 AC 109 ms
81,036 KB
testcase_35 AC 238 ms
86,412 KB
testcase_36 AC 87 ms
77,624 KB
testcase_37 AC 161 ms
84,036 KB
testcase_38 AC 127 ms
82,476 KB
testcase_39 AC 217 ms
86,120 KB
testcase_40 AC 63 ms
71,544 KB
testcase_41 AC 64 ms
71,092 KB
testcase_42 AC 181 ms
84,868 KB
testcase_43 AC 208 ms
85,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def primeset(N): #N以下の素数をsetで求める.エラトステネスの篩O(√Nlog(N))
    lsx = [1]*(N+1)
    for i in range(2,int(-(-N**0.5//1))+1):
        if lsx[i] == 1:
            for j in range(i,N//i+1):
                lsx[j*i] = 0
    setprime = set()
    for i in range(2,N+1):
        if lsx[i] == 1:
            setprime.add(i)
    return setprime
    
N = int(input())
if N == 1:
    print(0)
    exit()
setp = primeset(N)
lsp = list(setp)
lsp.sort()
P =len(lsp)
maxp = lsp[-1]
cnt = 0
for k in range(P):
    if lsp[k] ** 2 > maxp*2:
        break
    for j in range(P):
        if (lsp[k]**2 - lsp[j]) in setp:
            cnt += 1
print(cnt)
0