結果
問題 | No.473 和と積の和 |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:42:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 243 ms / 3,000 ms |
コード長 | 1,380 bytes |
コンパイル時間 | 195 ms |
コンパイル使用メモリ | 82,776 KB |
実行使用メモリ | 85,444 KB |
最終ジャッジ日時 | 2025-03-20 20:43:01 |
合計ジャッジ時間 | 5,414 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
import sysimport mathfrom functools import lru_cachesys.setrecursionlimit(1 << 25)def integer_nth_root(x, n):if x == 0:return 0low, high, best = 1, x, 0while low <= high:mid = (low + high) // 2try:val = mid ** nexcept OverflowError:high = mid - 1continueif val == x:return midelif val < x:best = midlow = mid + 1else:high = mid - 1return bestdef get_factors(n):factors = set()i = 1while i * i <= n:if n % i == 0:factors.add(i)factors.add(n // i)i += 1return sorted(factors)@lru_cache(maxsize=None)def count(current_product, k, min_factor):if k == 1:return 1 if current_product >= min_factor else 0max_d = integer_nth_root(current_product, k)lower = max(min_factor, 2)if lower > max_d:return 0factors = get_factors(current_product)res = 0for d in factors:if d > max_d:breakif d < lower:continueif current_product % d != 0:continueres += count(current_product // d, k - 1, d)return resn, x = map(int, input().split())y = x + 1required_min = 2 ** nprint(0 if y < required_min else count(y, n, 2))