結果

問題 No.2785 四乗足す四の末尾の0
ユーザー miho-4miho-4
提出日時 2024-06-14 21:57:26
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,133 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 82,788 KB
実行使用メモリ 77,812 KB
最終ジャッジ日時 2024-06-14 21:57:29
合計ジャッジ時間 3,337 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
68,432 KB
testcase_01 AC 73 ms
68,100 KB
testcase_02 AC 80 ms
68,084 KB
testcase_03 AC 75 ms
68,840 KB
testcase_04 AC 73 ms
68,168 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

prime = [True for i in range(10**6+1)]
def sieve_of_eratosthenes(n):
  p = 2
  while (p * p <= n):
    if (prime[p] == True):
      for i in range(p * 2, n+1, p):
        prime[i] = False
    p += 1
sieve_of_eratosthenes(10**6)

import random

def mr_test_normal(n: int):
    assert n > 1
    if n == 2:
        return True
    elif n%2 == 0:
        return False
    d = n - 1
    s = 0
    while d & 1 == 0:
        s += 1; d >>= 1
    
    k = 50
    for _ in range(k):
        a = random.randint(2, n-1)
        x = pow(a, d, n) # a^d mod n
        if x == 1 or x == n-1:
            continue
        for _ in range(s):
            x = pow(x, 2, n)
            if x == n-1: # a^(d*2^r) mod n
                break
        else: return False
    return True

n=int(input())
for _ in range(n):
  x=int(input())
  pr=x**4+4
  if x<=20:
    if prime[pr]:
      print("Yes")
    else:
      print("No")
  elif x%10==5:
    if mr_test_normal(pr):
      print("Yes")
    else:
      print("No")
  else:
    print("No")
  s=str(pr)
  cnt=0
  for i in range(len(s))[::-1]:
    if s[i]=="0":
      cnt+=1
    else:
      break
  print(cnt)
0