結果
| 問題 | 
                            No.2785 四乗足す四の末尾の0
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-06-14 22:04:44 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 954 ms / 2,000 ms | 
| コード長 | 860 bytes | 
| コンパイル時間 | 418 ms | 
| コンパイル使用メモリ | 82,228 KB | 
| 実行使用メモリ | 78,516 KB | 
| 最終ジャッジ日時 | 2024-06-14 22:04:51 | 
| 合計ジャッジ時間 | 6,033 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 | 
ソースコード
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=abs(int(input()))
  pr=x**4+4
  if x==1:
    print("Yes")
  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)