#d1203. 函数求和
函数求和
Sum of Function Values
Problem Description
You are given integers and a positive integer with .
Define the function to be the smallest satisfying ; when no such exists, .
Compute . Since the answer may be large, output it modulo .
Input Format
The first line contains two integers and .
The next line contains integers , the given numbers.
Output Format
One integer on a single line: the answer.
Sample Input 1
2 1
0 1
Sample Output 1
2
Sample Input 2
2 2
2 1
Sample Output 2
4
Sample Input 3
5 10
389 144 883 761 556
Sample Output 3
1118
Sample Explanation
For sample 1, , , so the answer is .
Constraints
For all data, and .