luogu#P5915. 冬至
冬至
Background
Spring is born and autumn dies, not knowing the Winter Solstice.
Problem Description
You are given the integers . You may choose numbers from them to form a string of length (repetition is allowed), and no substring is allowed to be a permutation of .
Find the total number of valid strings modulo .
Input Format
A single line with two positive integers .
Output Format
A single line with one integer, the total number of valid strings modulo .
3 2
2
7 7
818503
114514 233
782307368
Hint
[Sample 1 Explanation]
The valid strings that can be formed are: and .
All others are invalid, because they contain a permutation of . Therefore, the answer is .
[Sample 2 Explanation]
There are strings in total. Among them, are invalid (i.e. the number of permutations of ).
So the answer is , which is .
[Constraints]
For all testdata, , .
By: Bike (毕克).
Translated by ChatGPT 5