Count Pairs with Equal Product
Given an array of N integers, count the number of pairs (i, j) such that 0 <= i < j < N and A[i] * A[j] = K, for a given integer K. Note that A[i] and A[j] can be zero or negative.
Input
The first line contains two integers N and K, separated by a space. The second line contains N integers A[0], A[1], ..., A[N-1] separated by spaces.
Output
Print a single integer, the count of pairs (i, j) satisfying the conditions.
Constraints
1 <= N <= 200000, -10^9 <= K <= 10^9, -10^9 <= A[i] <= 10^9
Example 1
5 6 1 2 3 2 1
2
Pairs are (1,3) for 1*6, (2,3) for 2*3, (3,2) for 3*2, (2,3) for 2*3, (1,6) for 1*6. Wait, the values are: A[0]*A[2]=1*3=3, A[1]*A[2]=2*3=6, A[2]*A[3]=3*2=6. The pairs (i,j) with i<j are (1,2) for 2*3=6, and (2,3) for 3*2=6. So, count is 2.
Example 2
4 0 1 0 2 0
5
Pairs (i,j) with i<j and A[i]*A[j]=0 are (0,1), (0,3), (1,2), (1,3), (2,3). Count is 5.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 6 1 2 3 2 1
4 0 1 0 2 0