東京大学 情報理工学系研究科 創造情報学専攻 2007年8月実施 筆記試験 第1問
Author
Description
Let be the number of divisors of a positive integer . Let us compute the smallest for a given . Note that and are included among the divisors of .
(1) Calculate the smallest each for and .
(2) Let be prime factorized as where s are mutually different prime numbers and s are positive integers for . Describe in a mathematical formula.
(3) When is odd, what kind of number is ?
(4) Based on (2), describe the outline of a method to compute the smallest given . Moreover, describe ways to decrease computational complexity.
(5) Calculate the smallest for .
题目描述
设正整数 的正因数个数为 ,其中 和 本身也计入。现要对给定的 求满足条件的最小 。
-
分别在 和 时求最小的 。
-
若
其中 是两两不同的素数, 对 均为正整数,写出 的数学表达式。
-
当 为奇数时, 必须是哪一类数?
-
根据第 2 问,概述由给定 求最小 的方法,并说明如何降低计算复杂度。
-
求 时最小的 。
Kai
(1)
のとき、5は素数なので に限られ、最小は である。 では指数の候補は であり、最小の素数から割り当てるとそれぞれ となる。よって 。
(2)
の各正の約数は ()と一意に書ける。各指数の選び方は独立に 通りだから、
の場合は空積を1とする。
(3)
が奇数なら各 が奇数、従って各 が偶数である。ゆえに 。逆も成立する。 も含まれる。
(4)
最小解では小さい素数から順に使い、指数は非増加 にできる。未使用の小さい素数があれば置き換えるだけで が減り、 に を割り当てていれば、交換後と交換前の比は となるからである。
したがって の乗法的分割
を列挙し、 の最小値を取る。各因子は2以上なので深さは 以下である。残りの積の約数だけを候補とし、因子を非増加にして重複を避け、途中の積が既知の最良値以上になった枝は打ち切る。
def smallest_with_n_divisors(N):
if N < 1:
raise ValueError('N must be positive')
if N == 1:
return 1
primes = []
candidate = 2
while len(primes) < N.bit_length() - 1:
if all(candidate % p for p in primes if p * p <= candidate):
primes.append(candidate)
candidate += 1
best = 2 ** (N - 1) # always a feasible initial upper bound
def search(remaining, max_factor, depth, value):
nonlocal best
if remaining == 1:
best = min(best, value)
return
if depth == len(primes):
return
p = primes[depth]
power = p
for d in range(2, min(remaining, max_factor) + 1):
new_value = value * power # p ** (d - 1)
if new_value >= best:
break
if remaining % d == 0:
search(remaining // d, d, depth + 1, new_value)
power *= p
search(N, N, 0, 1)
return best
上の実装は簡明さのため候補 を走査している。実用上は を素因数分解し、各 remaining の約数一覧を生成・再利用すれば無駄な走査を減らせる。巨大な では整数そのものの桁数も大きくなるため、指数探索が単純な の全探索より効率的であっても、定数時間で解けるわけではない。
(5)
の非増加な乗法的分割を全て調べる。
| 最小の | |
|---|---|
最小は 。実際 の約数個数は である。