40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
'''
|
|
n = p1^k1 * p2^k2 * ... * pn^kn
|
|
then the diffrent solve number is ((2k1+1)(2k2+1)...(2kn+1)) / 2
|
|
'''
|
|
import math
|
|
from functools import reduce
|
|
from tools import number_theory
|
|
|
|
def updateList(limit, lst):
|
|
lst[0] = int(limit / reduce(lambda x, y: x * (2 * y + 1), lst[1:], 1) - 0.5) + 1
|
|
lst[0] = max(lst[:2])
|
|
|
|
def genList(limit, size):
|
|
result = []
|
|
base = [0] + [1] * (size - 1)
|
|
while True:
|
|
updateList(limit, base)
|
|
result.append(tuple(base))
|
|
if len(set(base)) == 1:
|
|
break
|
|
for i in range(1, size):
|
|
if base[i] < base[0]:
|
|
base[:i + 1] = [base[i] + 1] * (i + 1)
|
|
break
|
|
return result
|
|
|
|
def search(limit):
|
|
size_max = int(math.log2(limit))
|
|
prime = list(number_theory.make_prime(size_max * 2))
|
|
mini = 2 ** limit
|
|
for size in range(2, size_max):
|
|
mini = min(mini, min(
|
|
map(lambda x: reduce(lambda x, y: x * (y[0] ** y[1]),
|
|
zip(prime, x), 1),
|
|
genList(limit, size)
|
|
)))
|
|
return mini
|
|
|
|
print(search(4000000))
|