#P5487. 【模板】Berlekamp–Massey 算法
【模板】Berlekamp–Massey 算法
Description
You are given the first terms of a sequence starting from index .
Find the shortest linear recurrence of sequence modulo , and output modulo .
Input Format
The first line contains two integers , meaning that the first terms of sequence will be given, and you need to compute .
The second line contains integers, which are .
Output Format
On the first line, output the shortest linear recurrence.
On the second line, output the value of .
4 10
1 1 2 3
1 1
89
5 10
3 7 27 95 339
3 2
691707
Hint
For of the testdata, , , and the length of the recurrence is guaranteed to be at most .
Translated by ChatGPT 5
京公网安备 11011102002149号