結果

問題 No.811 約数の個数の最大化
ユーザー 双六双六
提出日時 2020-08-19 18:12:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 1,899 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 77,296 KB
最終ジャッジ日時 2024-04-20 09:41:29
合計ジャッジ時間 2,599 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,272 KB
testcase_01 AC 68 ms
70,272 KB
testcase_02 AC 170 ms
77,184 KB
testcase_03 AC 42 ms
54,400 KB
testcase_04 AC 49 ms
61,824 KB
testcase_05 AC 91 ms
76,800 KB
testcase_06 AC 87 ms
76,616 KB
testcase_07 AC 104 ms
77,056 KB
testcase_08 AC 125 ms
76,928 KB
testcase_09 AC 145 ms
76,928 KB
testcase_10 AC 125 ms
76,696 KB
testcase_11 AC 174 ms
77,064 KB
testcase_12 AC 107 ms
76,892 KB
testcase_13 AC 193 ms
77,296 KB
testcase_14 AC 186 ms
77,056 KB
権限があれば一括ダウンロードができます

ソースコード

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,61]
	L = [2]
	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 = defaultdict(int)
	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 main():
	N, K = getlist()
	D = primeFactor(N)
	ans = INF
	val = 0
	for i in range(N - 1, 0, -1):
		d = primeFactor(i)
		fac_cnt = 0
		for j in d:
			fac_cnt += min(d[j], D[j])

		if fac_cnt >= K:
			divnum = 1
			for j in d:
				divnum *= d[j] + 1

			if divnum >= val:
				ans = i
				val = divnum

	print(ans)

	

if __name__ == '__main__':
	main()
0