假设范围是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]

但我不知道这是否与解决方案有关。

最佳答案

提示:对于给定的带数字的上界,d_1 d_2 ... d_n考虑49n有多少个分区的小于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.

关于algorithm - 计算数字和为49的倍数的较大范围内的数字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43623935/

10-12 17:30