Pairs of elements
Practice
2.6 (21 votes)
Data structures
Basics of hash tables
Hash tables
Hashmap
Problem
88% Success 10107 Attempts 30 Points 10s Time Limit 256MB Memory 1024 KB Max Code

You are given an array of length \(N\). You are required to count the number of \((i, j)\) pairs where \(1⩽i<j⩽N\) such that the difference of the array elements on that indices is equal to the sum of the square of their indices.

That is the count of the number of pairs of \((i, j)\) such that it satisfies this equation (\(A[j] - A[i] = i^2 + j^2\)).

Input format 

  • The first line contains the length of the array \(N\). (\(1⩽N⩽10^5\))
  • The second line contains \(N\) integers representing array elements. (\(1⩽A[i]⩽10^{12}\))

Output format

Print the number of pairs that satisfy the provided condition.     

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
3 votes
Tags:
Data StructuresBasics of Hash TablesHash TablesHashmap
Points:30
17 votes
Tags:
SortingHashmapImplementationHash TablesData StructuresBasics of Hash TablesHashingMathObservation
Points:30
48 votes
Tags:
Ad-HocAlgorithmsApprovedHash MapsMediumOpen