Approach
Depth-first search
For ABC300 E — Dice Product 3, the implementation follows one branch at a time, making it suitable for components, trees, backtracking, or dependency exploration.
- Define the state carried into one recursive or stack frame.
- Mark or choose the current state before exploring children.
- Combine child results or undo the choice when the branch finishes.
Code notes
- 62 lines of Python from the credited upstream file abc300_e.py.
- The implementation keeps its working state in language-native values and containers.
- No explicit loop blocks detected.
Complexity
Count unique states for graph traversal; for backtracking, count the branching factor and maximum depth.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3 4def main():5 from functools import lru_cache6 7 import sys8 sys.setrecursionlimit(10 ** 8)9 10 input = sys.stdin.readline11 12 n = int(input())13 mod = 99824435314 inv = pow(5, mod - 2, mod) 15 16 17 18 19 two, three, five = 0, 0, 020 21 while n % 2 == 0:22 n = 223 two += 124 25 while n % 3 == 0:26 n = 327 three += 128 29 while n % 5 == 0:30 n = 5 31 five += 132 33 if n != 1:34 print(0)35 else:36 37 @lru_cache(maxsize=10 ** 6)38 def f(two, three, five):39 if (two, three, five) == (0, 0, 0):40 return 141 42 ans = 043 44 if two >= 1:45 ans += f(two - 1, three, five)46 if three >= 1:47 ans += f(two, three - 1, five)48 if two >= 2:49 ans += f(two - 2, three, five)50 if five >= 1:51 ans += f(two, three, five - 1)52 if two >= 1 and three >= 1:53 ans += f(two - 1, three - 1, five)54 55 return ans * inv % mod56 57 print(f(two, three, five))58 59 60if __name__ == "__main__":61 main()62