結果
| 問題 |
No.312 置換処理
|
| コンテスト | |
| ユーザー |
双六
|
| 提出日時 | 2020-08-19 18:37:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,899 bytes |
| コンパイル時間 | 263 ms |
| コンパイル使用メモリ | 82,380 KB |
| 実行使用メモリ | 88,936 KB |
| 最終ジャッジ日時 | 2024-10-12 05:09:03 |
| 合計ジャッジ時間 | 7,345 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 44 |
ソースコード
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")
def getlist():
return list(map(int, input().split()))
def gcd(a, b):
while b:
a, b = b, a % b
return a
def isPrimeMR(N):
d = N - 1
d = d // (d & -d)
L=[2,3,5,7,11,13,17,19,23,29,31,37]
for a in L:
t = d
y = pow(a, t, N)
if y == 1:
continue
while y != N - 1:
y = (y * y) % N
if y == 1 or t == N - 1:
return 0
return 1
def findFactorRho(N):
m = 1 << N.bit_length() // 8
for c in range(1, 99):
f = lambda x: (x * x + c) % N
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = f(y)
q = q * abs(x - y) % N
g = gcd(q, N)
k += m
r <<= 1
if g == N:
g = 1
while g == 1:
ys = f(ys)
g = gcd(abs(x - ys), N)
if g < N:
if isPrimeMR(g):
return g
elif isPrimeMR(N // g):
return N // g
return findFactorRho(g)
def primeFactor(N):
i = 2
ret = {}
rhoFlg = 0
while i * i <= N:
k = 0
while N % i == 0:
N //= i
k += 1
if k:
ret[i] = k
i += 1 + i % 2
if i == 101 and N >= 2 ** 20:
while N > 1:
if isPrimeMR(N):
ret[N], N = 1, 1
else:
rhoFlg = 1
j = findFactorRho(N)
k = 0
while N % j == 0:
N //= j
k += 1
ret[j] = k
if N > 1:
ret[N] = 1
if rhoFlg:
ret = {x: ret[x] for x in sorted(ret)}
return ret
def divisor(N):
fac = primeFactor(N)
div = [1]
for p, num in fac.items():
nex = []
for i in range(num + 1):
for j in div:
nex.append(j * (p ** i))
div = nex
return div
#処理内容
def main():
N = int(input())
div = divisor(N)
# print(div)
ans = N
for i in div:
if i > 2:
ans = min(ans, i)
print(ans)
if __name__ == '__main__':
main()
双六