Mod Pairs
Practice
3.6 (8 votes)
Math
Number theory
Modulus arithmetic
C++
Problem
63% Success 2375 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Given an array \(A\) of \(N\) elements, a prime number \(P\) and an integer \(K\). It is guaranteed all the elements in the array are distinct.

Find the number of pairs of indices \((i,j)\) such that \((1 \le i < j \le N)\) and \((A[i] + A[j]) \times (A[i]^2 + A[j]^2)) \equiv K \ \text{mod} \ P\) 

Note: 1 based indexing is followed.

Input format

  • The first line contains 3 space-separated integers \(N, P, K\).
  • The second line contains \(N\) space-separated integers denoting the array \(A\).

Output format

Print the number of pairs of indices which satisfy the given condition in a new line.

Constraints

\(2 \le N \le 10^5 \\ 0 \le K, A[i]\le P - 1 \\ 2 \le P \le 10^5\)

 

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:30
1 votes
Tags:
MediumMathNumber TheoryMedium
Points:30
Tags:
MediumModular arithmeticNumber Theory
Points:30
6 votes
Tags:
ArraysNumber TheoryData Structures1-DMathModulus Arithmetic