【问题标题】:Count the number in a big range whose digital sum is multiple of 49数一个大范围的数,其数字和是49的倍数
【发布时间】:2017-04-26 02:22:30
【问题描述】:

假设范围是int('1234567890' * 100)

我想计算有多少数字和是 49 的倍数。结果模 1000000007。

例如:

499999的数字和是49,是49的倍数,所以在1到499999的范围内,答案是1

我发现数字和似乎是周期性的。

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

但是不知道是不是和解决方案有关。

【问题讨论】:

    标签: algorithm dynamic


    【解决方案1】:

    提示:对于给定的数字上限,d_1 d_2 ... d_n 考虑有多少个分区有 49 少于 n 部分。然后问一个类似的问题,将d_1 从 0 逐步递增到其原始值。当它达到其原始值时,将d_2 设置为零并重复该过程。

    0 [...d_n] -> how many partitions of 49 with less than n parts?
    1 [...d_n] -> how many partitions of 49 - 1 with less than n parts?
    ...
    d_1, 0 [...d_n] -> how many partitions of 49 - d_1 with less than n-1 parts?
    d_1, 1 [...d_n] -> how many partitions of 49 - d_1 - 1 with less than n-1 parts?
    ...
    d_1, d_2, 0 [...d_n] -> num partitions of 49 - d_1 - d_2 with less than n-2 parts?
    etc.
    

    【讨论】:

    • 谢谢,我试试看。
    • @KIDJourney 感谢您接受答案。现在看这个;另一种可能更有效的方法可能是简单的digit DP。我还将研究基于具有素数的模算术进一步优化的可能性。
    猜你喜欢
    • 1970-01-01
    • 2019-06-25
    • 2013-11-24
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 2013-01-06
    相关资源
    最近更新 更多