結果

問題 No.843 Triple Primes
ユーザー mkawa2mkawa2
提出日時 2019-07-03 21:35:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 382 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 11,836 KB
実行使用メモリ 15,728 KB
最終ジャッジ日時 2023-10-19 17:58:09
合計ジャッジ時間 5,962 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,104 KB
testcase_01 AC 184 ms
15,728 KB
testcase_02 AC 30 ms
10,172 KB
testcase_03 AC 29 ms
10,156 KB
testcase_04 AC 31 ms
10,216 KB
testcase_05 AC 32 ms
10,160 KB
testcase_06 AC 31 ms
10,228 KB
testcase_07 AC 148 ms
14,656 KB
testcase_08 AC 169 ms
15,060 KB
testcase_09 AC 184 ms
15,696 KB
testcase_10 AC 156 ms
14,824 KB
testcase_11 AC 171 ms
15,280 KB
testcase_12 AC 183 ms
15,576 KB
testcase_13 AC 174 ms
15,428 KB
testcase_14 AC 175 ms
15,436 KB
testcase_15 AC 154 ms
14,728 KB
testcase_16 AC 161 ms
14,792 KB
testcase_17 AC 28 ms
10,104 KB
testcase_18 AC 28 ms
10,104 KB
testcase_19 AC 29 ms
10,104 KB
testcase_20 AC 69 ms
11,460 KB
testcase_21 AC 50 ms
10,728 KB
testcase_22 AC 111 ms
13,092 KB
testcase_23 AC 114 ms
13,448 KB
testcase_24 AC 74 ms
11,520 KB
testcase_25 AC 63 ms
11,252 KB
testcase_26 AC 182 ms
15,680 KB
testcase_27 AC 37 ms
10,220 KB
testcase_28 AC 173 ms
15,480 KB
testcase_29 AC 73 ms
11,596 KB
testcase_30 AC 178 ms
15,604 KB
testcase_31 AC 42 ms
10,464 KB
testcase_32 AC 35 ms
10,208 KB
testcase_33 AC 79 ms
11,980 KB
testcase_34 AC 104 ms
12,916 KB
testcase_35 AC 183 ms
15,696 KB
testcase_36 AC 57 ms
11,160 KB
testcase_37 AC 149 ms
14,488 KB
testcase_38 AC 133 ms
13,820 KB
testcase_39 AC 173 ms
15,528 KB
testcase_40 AC 29 ms
10,104 KB
testcase_41 AC 29 ms
10,104 KB
testcase_42 AC 157 ms
14,928 KB
testcase_43 AC 168 ms
15,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#エネストラバージョン
n=int(input())
if n==1:
    print(0)
    exit()
elif n==2:
    print(1)
    exit()
TF=[0,1]*(n//2+1)
TF[1]=0
TF[2]=1
primes=[]
for p in range(3,n+1):
    if TF[p]==0:continue
    primes.append(p)
    for i in range(p**2,n+1,p):
        TF[i]=0
cnt=0
for r in primes:
    p=r**2-2
    if p>n:
        break
    if TF[p]:
        cnt+=1
print(cnt*2+1)
0