Plot the Curve
Practice
3.7 (16 votes)
Data structures
Easy
Hash maps
Hash tables
Problem
56% Success 5666 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given with integers \(a, b, c, d, m\). These represent the modular equation of a curve \( y^2 mod\ m = (ax^3+bx^2+cx+d)\ mod\ m\)

Also, you are provided with an array \(A\) of size \(N\). Now, your task is to find the number of pairs in the array that satisfy the given modular equation.

If $$(A_i, A_j)$$ is a pair then \( A_j^2 mod \ m = (aA_i^3+bA_i^2+cA_i+d)\ mod\ m\).

Since the answer could be very large output it modulo $$10^9 + 7$$.

Note: A pair is counted different from some other pair if either $$A_i$$ of the two pairs is different or $$A_j$$ of the two pairs is different. Also for the convenience of calculations, we may count \((A_i,A_i)\) as a valid pair if it satisfies given constraints.

Input Format
First line of the input contains number of test cases \(T\).
First line for each test case consists of $$5$$ space-separated integers \(a, b, c, d, m\), corresponding to modular equation given.
Next line contains a single integer \(N\).
Next line contains \(N\) space-separated integers corresponding to values of array \(A\).

Output Format
For each test case, output a single line corresponding to number of valid pairs in the array mod \(10^9+7\).

Constraints
\(1 \le T \le 10\\ 1 \le N \le10^5\\ -2 \times10^9 \le a,b,c,d,A_i \le 2 \times 10^9\\ 1 \le m \le 2 \times 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
4 votes
Tags:
Data StructuresHash TablesBasics of Hash TablesReal world
Points:20
50 votes
Tags:
ApprovedBasic ProgrammingEasyHash MapsOpen
Points:20
16 votes
Tags:
Accessing MapsData StructuresEasyHash TablesImplementationPriority queueString Manipulation