Beautiful Numbers
HardRating 1800CodeforcesMixed Practice
Approach hintTry it first, then revealHide
Fix the number i of digits equal to a. The digit sum i * a + (n - i) * b can be checked directly, and each valid i adds C(n, i), computed from precomputed factorials and modular inverses.