Find pairs
Practice
3.8 (29 votes)
Basic programming
Problem
18% Success 10076 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Given an array \(A\) of length \(N\). Find the number of ordered pairs \((i, j)\) which satisfy the given condition
- \((A[i] - A[j]) / (i - j) = 1\)
- \(A[i] - A[j]\) should be divisible by \(i-j\)
- \(i \neq j\)
Input format
- The first line contains an integer \(N\).
- The second line of each test case contains \(N\) space-separated integers, denoting the elements of array \(A\).
Output format
Print the number of ordered pairs (i, j) which satisfy the above condition in a new line.
Constraints
\(1 \le N \le 5 \times 10 ^ 5\)
\(1 \le A[i] \le 10^6\)
Explanation
For every pair \((i, j)\) in this array where \(i \neq j\), it satisfy the condition in the problem statement. Hence, the answer is 6.
Code Editor
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
9 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementationString Manipulation
Points:20
52 votes
Tags:
Ad-HocApprovedEasyOpen
3.Diamonds
Points:20
308 votes
Tags:
Ad-HocAd-hocApprovedBasic ProgrammingEasyHiringOpenReadyRoot
Editorial
Login to unlock the editorial
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
Results
Custom Input
Run your code to see the output