In an array
Practice
2.5 (40 votes)
1 D array
Arrays
Data structures
Easy
One Dimensional
Open
Approved
Problem
86% Success 9676 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an array \(A\) of size \(N\), where the \(i^{th}\) integer of the array is \(A[i]\) and its value ranges between \(1\) and \(1000\) inclusive. You are required to complete the following task:

Assume that you are provided with \(3\) additional numbers \(K\), \(X\), and \(Y\). Your task is to report the number of unordered pairs of elements \((i,j)\) from this array, such that \( (1 \le i < j \le N)\), \((A[i]+A[j]) \%K=X\), and \((A[i] \times A[j]) \%K=Y\).

Input format

  • First line: Four space-separated integers \(N\), \(K\)\(X\), and \(Y\)
  • Next line: \(N\) space-separated integers where the \(i^{th}\) integer denotes \(A[i]\)

Output format

Print the required number of ordered pairs of array elements in a single line. As the answer could be rather large, be careful of integer overflows.

Constraints

\( 2 \le N \le 10^5 \)

\( 1 \le K \le 10^6 \)

\( 0 \le X , Y < K \)

\( 1 \le A[i] \le 1000 \)

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
7 votes
Tags:
HashmapHashingCounting and ArrangementsData StructuresMathArrays1-D
Points:30
126 votes
Tags:
Data StructuresImplementationMediumOne-dimensionalSets
Points:30
22 votes
Tags:
ArraysData StructuresMediumOne-dimensionalStandard Template Library