結果
問題 | No.2016 Countdown Divisors |
ユーザー | Theta |
提出日時 | 2022-10-26 16:23:18 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,249 bytes |
コンパイル時間 | 82 ms |
コンパイル使用メモリ | 10,864 KB |
実行使用メモリ | 8,816 KB |
最終ジャッジ日時 | 2023-09-17 09:33:37 |
合計ジャッジ時間 | 3,823 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
8,816 KB |
testcase_01 | TLE | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
ソースコード
from functools import lru_cache, reduce from operator import mul import sys from itertools import count sys.setrecursionlimit(100000) @lru_cache def calc_positive_divisors_num(num: int) -> int: if num <= 0: raise ValueError if num == 1: return 1 if num == 2: return 2 factors = calc_prime_factorize(num) return reduce(mul, map(lambda num: num + 1, factors.values())) @lru_cache def calc_prime_factorize(num: int) -> dict[int, int]: if num < 2: raise ValueError divisors = {} for divisor in count(2): if divisor ** 2 > num: if num != 1: divisors[num] = 1 break while num % divisor == 0 and num != 1: try: divisors[divisor] += 1 except KeyError: divisors[divisor] = 1 num //= divisor return divisors @lru_cache def countdown_divisors(num: int) -> int: divisors_num = calc_positive_divisors_num(num) if num == divisors_num: return num return countdown_divisors(num - divisors_num) def main(): for _ in range(int(input())): N = int(input()) print(countdown_divisors(N)) if __name__ == "__main__": main()