結果

問題 No.843 Triple Primes
ユーザー るこーそーるこーそー
提出日時 2024-09-09 12:55:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 721 ms / 2,000 ms
コード長 626 bytes
コンパイル時間 412 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 81,724 KB
最終ジャッジ日時 2024-09-09 12:56:18
合計ジャッジ時間 19,498 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,700 KB
testcase_01 AC 701 ms
81,288 KB
testcase_02 AC 113 ms
77,284 KB
testcase_03 AC 102 ms
77,476 KB
testcase_04 AC 119 ms
77,688 KB
testcase_05 AC 105 ms
77,384 KB
testcase_06 AC 114 ms
77,292 KB
testcase_07 AC 586 ms
80,652 KB
testcase_08 AC 639 ms
80,856 KB
testcase_09 AC 721 ms
81,144 KB
testcase_10 AC 603 ms
80,832 KB
testcase_11 AC 680 ms
81,124 KB
testcase_12 AC 684 ms
81,364 KB
testcase_13 AC 695 ms
81,404 KB
testcase_14 AC 664 ms
80,928 KB
testcase_15 AC 616 ms
80,864 KB
testcase_16 AC 599 ms
80,568 KB
testcase_17 AC 43 ms
54,520 KB
testcase_18 AC 43 ms
54,256 KB
testcase_19 AC 44 ms
55,808 KB
testcase_20 AC 306 ms
78,640 KB
testcase_21 AC 190 ms
78,028 KB
testcase_22 AC 436 ms
79,664 KB
testcase_23 AC 477 ms
79,820 KB
testcase_24 AC 273 ms
78,652 KB
testcase_25 AC 232 ms
78,324 KB
testcase_26 AC 710 ms
81,308 KB
testcase_27 AC 150 ms
77,868 KB
testcase_28 AC 675 ms
81,332 KB
testcase_29 AC 286 ms
78,524 KB
testcase_30 AC 720 ms
81,724 KB
testcase_31 AC 160 ms
77,692 KB
testcase_32 AC 134 ms
77,664 KB
testcase_33 AC 306 ms
78,616 KB
testcase_34 AC 415 ms
79,544 KB
testcase_35 AC 697 ms
81,364 KB
testcase_36 AC 226 ms
78,080 KB
testcase_37 AC 584 ms
80,404 KB
testcase_38 AC 492 ms
79,836 KB
testcase_39 AC 698 ms
81,052 KB
testcase_40 AC 43 ms
55,000 KB
testcase_41 AC 44 ms
54,948 KB
testcase_42 AC 618 ms
80,860 KB
testcase_43 AC 656 ms
81,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
def MillerRabin(n,k=20):
  if n==2:return True
  if n<2 or n%2==0:return False
  s,d=0,n-1
  while d&1==0:
    s+=1
    d>>=1
  for _ in range(k):
    a=random.randint(1,n-1)
    x=pow(a,d,n)
    if x!=1 and x!=n-1:
      for __ in range(s):
        x=pow(x,2,n)
        if x==n-1:break 
      else:return False
  return True

n=int(input())
primes=[True]*(n+1)
primes[0]=primes[1]=False
for p in range(2,n+1):
  if MillerRabin(p):
    for q in range(2*p,n+1,p):
      primes[q]=False

ans=1
for r in range(3,n):
  if r*r-2>n:break
  if MillerRabin(r*r-2) and MillerRabin(r):
    ans+=2

print(ans if n>1 else 0)
0