Digit Division
题目链接:
http://acm.hust.edu.cn/vjudge/contest/127407#problem/D
Description
We are given a sequence of n decimal digits. The sequence needs to be partitioned into one or more contiguous subsequences such that each subsequence, when interpreted as a decimal number, is divisible by a given integer m. Find the number of different such partitions modulo 109+7. When determining if two partitions are different, we only consider the locations of subsequence boundaries rather than the digits themselves, e.g. partitions 2|22 and 22|2 are considered different.Input
The input file contains several test cases, each of them as described below. The first line contains two integers n and m (1 ≤ n ≤ 300000, 1 ≤ m ≤ 1000000) — the length of the sequence and the divisor respectively. The second line contains a string consisting of exactly n digits.Output
For each test case, output a single integer — the number of different partitions modulo 109 + 7 on a line by itself.Sample Input
4 2 1246 4 7 2015Sample Output
4 0##题意: 求有多少种方式把一个数串划分成多段,使得每段组成的数字能被m整除.
##题解: 先从整体考虑,如果能被划分成满足条件的若干段,那么整个原串组成的数字必定满足条件. (若A,B都能被m整除,则AB=A*100...+B一定能被m整除) 再考虑把原串划分成两段,当且仅当某个前缀组成的数能被m整除时,原串才能被分成两段. 划成多段同理. 那么结果就是,求有多少个前缀能恰好被m整除. 若有m个(不包括末尾),结果就是 2^m. (相当于枚举每个位置分割or不分割).
##代码: ``` cpp #include