結果

問題 No.843 Triple Primes
ユーザー 山本信二山本信二
提出日時 2022-04-06 15:53:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 812 ms / 2,000 ms
コード長 594 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 13,920 KB
最終ジャッジ日時 2023-08-18 13:38:43
合計ジャッジ時間 21,095 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
11,920 KB
testcase_01 AC 812 ms
13,780 KB
testcase_02 AC 70 ms
11,976 KB
testcase_03 AC 70 ms
12,068 KB
testcase_04 AC 74 ms
11,940 KB
testcase_05 AC 70 ms
11,916 KB
testcase_06 AC 71 ms
11,912 KB
testcase_07 AC 647 ms
13,640 KB
testcase_08 AC 723 ms
13,624 KB
testcase_09 AC 808 ms
13,748 KB
testcase_10 AC 633 ms
13,620 KB
testcase_11 AC 745 ms
13,828 KB
testcase_12 AC 774 ms
13,904 KB
testcase_13 AC 780 ms
13,920 KB
testcase_14 AC 759 ms
13,780 KB
testcase_15 AC 617 ms
13,564 KB
testcase_16 AC 632 ms
13,516 KB
testcase_17 AC 68 ms
11,756 KB
testcase_18 AC 68 ms
12,084 KB
testcase_19 AC 68 ms
11,920 KB
testcase_20 AC 201 ms
12,704 KB
testcase_21 AC 134 ms
12,516 KB
testcase_22 AC 404 ms
13,208 KB
testcase_23 AC 420 ms
13,224 KB
testcase_24 AC 208 ms
12,740 KB
testcase_25 AC 165 ms
12,356 KB
testcase_26 AC 807 ms
13,772 KB
testcase_27 AC 87 ms
11,968 KB
testcase_28 AC 767 ms
13,832 KB
testcase_29 AC 226 ms
12,744 KB
testcase_30 AC 791 ms
13,872 KB
testcase_31 AC 100 ms
12,068 KB
testcase_32 AC 83 ms
11,984 KB
testcase_33 AC 243 ms
12,648 KB
testcase_34 AC 383 ms
13,112 KB
testcase_35 AC 793 ms
13,836 KB
testcase_36 AC 149 ms
12,512 KB
testcase_37 AC 612 ms
13,640 KB
testcase_38 AC 477 ms
13,252 KB
testcase_39 AC 778 ms
13,828 KB
testcase_40 AC 65 ms
12,064 KB
testcase_41 AC 68 ms
11,920 KB
testcase_42 AC 689 ms
13,568 KB
testcase_43 AC 760 ms
13,832 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