結果

問題 No.843 Triple Primes
ユーザー takakintakakin
提出日時 2020-05-24 19:14:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 882 ms / 2,000 ms
コード長 557 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-04-20 06:43:49
合計ジャッジ時間 19,589 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
10,752 KB
testcase_01 AC 867 ms
16,384 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 AC 29 ms
10,752 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 29 ms
10,624 KB
testcase_06 AC 32 ms
10,880 KB
testcase_07 AC 692 ms
15,232 KB
testcase_08 AC 667 ms
15,616 KB
testcase_09 AC 876 ms
16,256 KB
testcase_10 AC 722 ms
15,360 KB
testcase_11 AC 725 ms
15,872 KB
testcase_12 AC 855 ms
16,128 KB
testcase_13 AC 748 ms
16,000 KB
testcase_14 AC 868 ms
16,128 KB
testcase_15 AC 652 ms
15,232 KB
testcase_16 AC 709 ms
15,488 KB
testcase_17 AC 29 ms
10,752 KB
testcase_18 AC 29 ms
10,752 KB
testcase_19 AC 28 ms
10,624 KB
testcase_20 AC 180 ms
12,160 KB
testcase_21 AC 94 ms
11,708 KB
testcase_22 AC 423 ms
14,424 KB
testcase_23 AC 450 ms
14,456 KB
testcase_24 AC 184 ms
12,288 KB
testcase_25 AC 143 ms
12,032 KB
testcase_26 AC 839 ms
16,304 KB
testcase_27 AC 53 ms
11,136 KB
testcase_28 AC 795 ms
16,000 KB
testcase_29 AC 200 ms
12,416 KB
testcase_30 AC 856 ms
16,248 KB
testcase_31 AC 62 ms
11,136 KB
testcase_32 AC 43 ms
11,008 KB
testcase_33 AC 212 ms
12,672 KB
testcase_34 AC 362 ms
14,228 KB
testcase_35 AC 882 ms
16,364 KB
testcase_36 AC 121 ms
11,916 KB
testcase_37 AC 593 ms
15,104 KB
testcase_38 AC 521 ms
14,576 KB
testcase_39 AC 773 ms
16,128 KB
testcase_40 AC 26 ms
10,752 KB
testcase_41 AC 25 ms
10,624 KB
testcase_42 AC 755 ms
15,488 KB
testcase_43 AC 791 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