#P18103. [CCPC 2026 长春站] 余镜
[CCPC 2026 长春站] 余镜
Problem Description
While tidying up a folding mirror made of mirror pieces, Little R finds that after taking the sequence modulo an integer , some intervals turn into palindromes.
For positive integers (), if is a palindromic sequence (that is, holds for every ), define ; otherwise define .
Given the upper bound , please compute:
Input Format
The first line contains two integers (, ), representing the length of the sequence and the upper bound of the modulus.
The second line contains integers (), representing the sequence .
Output Format
Output a single line with one integer, which is the required answer $\sum\limits_{1\le l<r\le n}\ \sum\limits_{2\le m\le M} f(l,r,m)$.
The answer may be very large, so please use 64-bit integers.
5 4
1 3 2 4 3
3
Hint
In total there are the following triples with :
- : here is a palindromic sequence.
- : here is a palindromic sequence.
- : here $[a_2\bmod 2,\ a_3\bmod 2,\ a_4\bmod 2,\ a_5\bmod 2]=[1,0,0,1]$ is a palindromic sequence.
For , $[a_2\bmod 3,\ a_3\bmod 3,\ a_4\bmod 3,\ a_5\bmod 3]=[0,2,1,0]$ is not a palindromic sequence, so .
Translated by QwenWork