結果

問題 No.312 置換処理
ユーザー 双六双六
提出日時 2020-08-19 18:37:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,899 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 82,144 KB
実行使用メモリ 88,648 KB
最終ジャッジ日時 2024-04-20 09:42:56
合計ジャッジ時間 7,166 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0