結果
| 問題 |
No.2785 四乗足す四の末尾の0
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-14 21:54:04 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,468 bytes |
| コンパイル時間 | 347 ms |
| コンパイル使用メモリ | 82,568 KB |
| 実行使用メモリ | 86,596 KB |
| 最終ジャッジ日時 | 2024-06-14 21:54:10 |
| 合計ジャッジ時間 | 5,587 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 TLE * 1 -- * 4 |
ソースコード
# 高速素数判定
import random
def Miller_Rabin_fast(n, k):
if n==2: return "prime"
if n%2==0: return "composite"
s, d=0, n-1
while d%2==0:
s, d=s+1, d//2
if n<4759123141:
test=(2,7,61)
for a in test:
if a>n-1: continue
check=[]
check.append(pow(a, d, n)==1)
for r in range(s):
check.append(pow(a, pow(2, r)*d, n)==n-1)
if True in check:
continue
else:
return "composite"
return "prime"
elif n<=pow(2, 64):
test=(2,325,9375,28178,450775,9780504,1795265022)
for a in test:
if a>n-1: continue
check=[]
check.append(pow(a, d, n)==1)
for r in range(s):
check.append(pow(a, pow(2, r)*d, n)==n-1)
if True in check:
continue
else:
return "composite"
return "prime"
else:
for _ in range(k):
a=random.randint(1, n-1)
check=[]
check.append(pow(a, d, n)==1)
for r in range(s):
check.append(pow(a, pow(2, r)*d, n)==n-1)
if True in check:
continue
else:
return "composite"
return "probably_prime"
_10=[10**i for i in range(43)]
def ord_10(n):
ok = 0
ng = 42
while abs(ok-ng)>1:
mid=(ok+ng)//2
if n%_10[mid]==0:
ok=mid
else:
ng=mid
return ok
T=int(input())
for _ in range(T):
N=int(input())
if Miller_Rabin_fast(N*N*N*N+4, 10)!="composite":
print("Yes")
else:
print("No")
print(ord_10(N*N*N*N+4))