Help me out with this question

you are given a array of positive integers a and a number x print number of pairs such that i<j and a[i]==a[j] and i*j should be divisible by x
(solved in o(n2)) need an optimal solution
array indexing 1 based
example=[2,2,2] x=2
arr[i]=2 for all valid i and the valid indices are [1,2] and [2,3]
so output should be 2