Scott's New Trick
https://www.facebook.com/codingcompetitions/hacker-cup/2011/round-2/problems/B
Last updated
https://www.facebook.com/codingcompetitions/hacker-cup/2011/round-2/problems/B
Last updated
Little Scott recently learned how to perform arithmetic operations modulo some prime number P. As a training set, he picked two sequences a of length N and b of length M, generated in the following way:
, for
, for
Now he wants to find the number of pairs , were and , such that , for given number L. He asked you to do the same to help him check his answers.
The first line of input file consists of a single number T, the number of test cases. Each test consists of three lines. The first line of a test case contains two integers: prime number P and positive integer L. The second line consists of six non-negative integers N, A1, A2, A3, A4, A5. Likewise, the third line contains six non-negative integers M, B1, B2, B3, B4, B5.
P is guaranteed prime
Output T lines, with the answer to each test case on a single line.