結果

問題 No.843 Triple Primes
ユーザー suakiisuakii
提出日時 2021-04-28 10:33:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 824 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 13,956 KB
最終ジャッジ日時 2023-09-21 11:05:41
合計ジャッジ時間 19,392 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
11,896 KB
testcase_01 AC 805 ms
13,716 KB
testcase_02 AC 66 ms
12,108 KB
testcase_03 AC 65 ms
11,892 KB
testcase_04 AC 67 ms
11,856 KB
testcase_05 AC 65 ms
11,892 KB
testcase_06 AC 67 ms
11,944 KB
testcase_07 AC 613 ms
13,440 KB
testcase_08 AC 667 ms
13,448 KB
testcase_09 AC 790 ms
13,724 KB
testcase_10 AC 640 ms
13,596 KB
testcase_11 AC 717 ms
13,780 KB
testcase_12 AC 758 ms
13,956 KB
testcase_13 AC 746 ms
13,700 KB
testcase_14 AC 766 ms
13,888 KB
testcase_15 AC 631 ms
13,592 KB
testcase_16 AC 657 ms
13,636 KB
testcase_17 AC 63 ms
12,032 KB
testcase_18 AC 63 ms
12,072 KB
testcase_19 AC 62 ms
11,928 KB
testcase_20 AC 195 ms
12,572 KB
testcase_21 AC 125 ms
12,388 KB
testcase_22 AC 403 ms
13,088 KB
testcase_23 AC 421 ms
13,200 KB
testcase_24 AC 202 ms
12,364 KB
testcase_25 AC 165 ms
12,444 KB
testcase_26 AC 824 ms
13,776 KB
testcase_27 AC 82 ms
11,900 KB
testcase_28 AC 734 ms
13,828 KB
testcase_29 AC 219 ms
12,808 KB
testcase_30 AC 786 ms
13,724 KB
testcase_31 AC 96 ms
11,988 KB
testcase_32 AC 81 ms
12,020 KB
testcase_33 AC 235 ms
12,676 KB
testcase_34 AC 379 ms
13,272 KB
testcase_35 AC 769 ms
13,784 KB
testcase_36 AC 146 ms
12,516 KB
testcase_37 AC 606 ms
13,456 KB
testcase_38 AC 465 ms
13,300 KB
testcase_39 AC 771 ms
13,724 KB
testcase_40 AC 64 ms
12,124 KB
testcase_41 AC 63 ms
11,704 KB
testcase_42 AC 670 ms
13,600 KB
testcase_43 AC 715 ms
13,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
isPrime = [True]*500005

# print(isPrime)

def makePrime():
  isPrime[0] = False
  isPrime[1] = False

  n = int(math.sqrt(500005))


  for i in range(2, n+1):
      if (not isPrime[i]):
          continue
      for j in range(i*2, 500005, i):
          isPrime[j] = False


makePrime()
p = []
N = int(input())
for i in range(2, N+1):
    if isPrime[i]:
        p.append(i)

# print(p)
ans = 0

for i in range(len(p)):
    for j in range(len(p)):
        t = p[i] * p[i] - p[j]
        if (t < 1 or t > N):
            break
        if (isPrime[t]):
            ans += 1

print(ans)
0