結果
| 問題 |
No.375 立方体のN等分 (1)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 22:42:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 5,000 ms |
| コード長 | 2,396 bytes |
| コンパイル時間 | 187 ms |
| コンパイル使用メモリ | 81,724 KB |
| 実行使用メモリ | 76,480 KB |
| 最終ジャッジ日時 | 2025-04-15 22:44:05 |
| 合計ジャッジ時間 | 3,032 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 |
ソースコード
import math
def prime_factors(n):
factors = {}
while n % 2 == 0:
factors[2] = factors.get(2, 0) + 1
n = n // 2
i = 3
while i * i <= n:
while n % i == 0:
factors[i] = factors.get(i, 0) + 1
n = n // i
i += 2
if n > 1:
factors[n] = 1
return factors
def generate_divisors(factors):
divisors = [1]
for p, exp in factors.items():
current_length = len(divisors)
for e in range(1, exp + 1):
pe = p ** e
for i in range(current_length):
divisors.append(divisors[i] * pe)
return sorted(divisors)
def cube_root(n):
low = 1
high = n
while low <= high:
mid = (low + high) // 2
if mid ** 3 <= n:
low = mid + 1
else:
high = mid - 1
return high
def main():
N = int(input().strip())
if N == 1:
print("0 0")
return
factors_N = prime_factors(N)
divisors_N = generate_divisors(factors_N)
crn = cube_root(N)
candidates_a = [a for a in divisors_N if a <= crn and a <= N]
min_sum = float('inf')
for a in candidates_a:
if N % a != 0:
continue
M = N // a
if M == 0:
continue
factors_M = {}
for p in factors_N:
exp_a = 0
temp = a
while temp % p == 0:
exp_a += 1
temp = temp // p
exp_M = factors_N[p] - exp_a
if exp_M > 0:
factors_M[p] = exp_M
if not factors_M:
current_sum = a + 1 + 1
if current_sum < min_sum:
min_sum = current_sum
continue
divisors_M = generate_divisors(factors_M)
divisors_M_sorted = sorted(divisors_M)
sqrt_M = math.sqrt(M)
max_b = None
for b in reversed(divisors_M_sorted):
if b > sqrt_M:
continue
if b < a:
continue
c = M // b
if c >= b:
max_b = b
break
if max_b is None:
continue
c = M // max_b
current_sum = a + max_b + c
if current_sum < min_sum:
min_sum = current_sum
Tmin = min_sum - 3
Tmax = N - 1
print(f"{Tmin} {Tmax}")
if __name__ == "__main__":
main()
lam6er