100 atcoder#AGC061F. [AGC061F] Perfect Strings
[AGC061F] Perfect Strings
Score : points
Problem Statement
There are positive integers and .
A binary string is called good if all of the followings are satisfied:
- is non-empty.
- The number of
1s in is a multiple of . - The number of
0s in is a multiple of .
A good string is called perfect if it doesn't contain shorter good (contiguous) substrings. For example, if and , then strings 111, 00 and 10101 are perfect, but 0000 and 11001 are not.
One can show that for any the number of perfect strings is finite. Find this number modulo .
Constraints
- All values in the input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2 2
4
The perfect strings are 00, 0101, 1010, 11.
3 2
7
The perfect strings are 00, 01011, 01101, 10101, 10110, 11010, 111.
23 35
212685109