結果

問題 No.843 Triple Primes
ユーザー takakintakakin
提出日時 2020-05-24 19:22:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,012 ms / 2,000 ms
コード長 557 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 16,280 KB
最終ジャッジ日時 2024-04-20 07:04:46
合計ジャッジ時間 21,849 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,624 KB
testcase_01 AC 980 ms
16,280 KB
testcase_02 AC 35 ms
10,624 KB
testcase_03 AC 33 ms
10,624 KB
testcase_04 AC 36 ms
10,880 KB
testcase_05 AC 35 ms
10,752 KB
testcase_06 AC 38 ms
10,880 KB
testcase_07 AC 744 ms
15,248 KB
testcase_08 AC 820 ms
15,616 KB
testcase_09 AC 972 ms
16,248 KB
testcase_10 AC 772 ms
15,360 KB
testcase_11 AC 853 ms
16,000 KB
testcase_12 AC 929 ms
16,128 KB
testcase_13 AC 905 ms
15,916 KB
testcase_14 AC 902 ms
16,072 KB
testcase_15 AC 752 ms
15,232 KB
testcase_16 AC 748 ms
15,360 KB
testcase_17 AC 31 ms
10,752 KB
testcase_18 AC 31 ms
10,624 KB
testcase_19 AC 31 ms
10,752 KB
testcase_20 AC 192 ms
12,160 KB
testcase_21 AC 108 ms
11,592 KB
testcase_22 AC 476 ms
14,300 KB
testcase_23 AC 479 ms
14,328 KB
testcase_24 AC 200 ms
12,288 KB
testcase_25 AC 156 ms
11,904 KB
testcase_26 AC 930 ms
16,256 KB
testcase_27 AC 52 ms
10,880 KB
testcase_28 AC 895 ms
16,000 KB
testcase_29 AC 220 ms
12,288 KB
testcase_30 AC 930 ms
16,256 KB
testcase_31 AC 69 ms
11,136 KB
testcase_32 AC 48 ms
10,880 KB
testcase_33 AC 241 ms
12,672 KB
testcase_34 AC 426 ms
14,228 KB
testcase_35 AC 1,012 ms
16,256 KB
testcase_36 AC 135 ms
11,904 KB
testcase_37 AC 681 ms
15,104 KB
testcase_38 AC 530 ms
14,576 KB
testcase_39 AC 938 ms
16,128 KB
testcase_40 AC 32 ms
10,624 KB
testcase_41 AC 32 ms
10,752 KB
testcase_42 AC 814 ms
15,616 KB
testcase_43 AC 843 ms
15,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())

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
  return [i for i in range(n+1) if is_prime[i]]
ans=0
P=primes(n)
SP=set(P)
for p in P:
  if p**2>2*n:
    break
  else:
    for q in P:
      if 2*q>p**2:
        break
      else:
        if p**2-q in SP:
          ans+=1
          if 2*q!=p**2:
            ans+=1
print(ans)
0