luogu#P5137. polynomial
polynomial
Background
Wolfycz really likes polynomials (just kidding).
Problem Description
Wolfycz likes studying polynomials, and especially likes simple problems like . We know that , but Wolfycz is not satisfied with such an expression, so he changes all coefficients to , i.e. . However, Wolfycz finds that he is not skilled enough and cannot compute the answer, so he hopes you can help him.
UPD: Please pay attention to the impact of constant factors on runtime efficiency.
Input Format
The first line contains , meaning there are test cases.
Each of the next lines contains four integers .
Output Format
Output lines. Each line contains one integer, representing the value of .
5
12 78 35 317
35 57 19 193
94 31 75 571
64 80 14 857
74 16 42 751
254
24
283
796
407
Hint
For of the testdata, .
For of the testdata, .
UPD: is not guaranteed to be prime.
Translated by ChatGPT 5