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.
Submissions
Please login to view your submissions
Similar Problems
Points:30
17 votes
Tags:
SortingHashmapImplementationHash TablesData StructuresBasics of Hash TablesHashingMathObservation
Points:30
88 votes
Tags:
ApprovedBinary SearchMediumOpenSorting
3.LongLong
Points:30
62 votes
Tags:
ApprovedBinary SearchHash MapsMediumOpenString Manipulation
Editorial