假设范围为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]
但我不知道它是否与解决方案有关。
答案 0 :(得分: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.