Apply binary search on the answer, one only needs to check whether can be represented as the sum of increasing numbers. The key observation is that a number is increasing if and only if it can be represented as the sum of exactly repunits, where a repunit is a number in the form or . Therefore, one only needs to check whether can be represented as the sum of repunits. Since all repunits has the form of , the condition holds if and only if can be represented as the sum of numbers of the form , which is equivalent to whether the digit sum of is no more than . This can be easily checked. With a trivial greedy algorithm which decreases the number by the maximum possible repdigit, one can easily show that the answer has an upper bound of . Therefore, the problem can be solved in the time complexity of .
[AGC011E] Increasing Numbers Tutorial
文章信息与版本
文章信息
- 收录
- 2025年12月12日
- 更新
- 2025年12月12日
- 篇幅
- 约 2 分钟
- 获赞
- 2