Pair Count

3.7

245 votes
Mathematics, Sieve, Approved, Easy-Medium
Problem

You are given an array A={a0,a1...aN1} and an integer D. Find the total number of un-ordered pairs (i,j) where ij such that aiaj0(modD).

INPUT

The first line of each test file contains two space separated integers N and D, where N denotes the size of array A and D is as described above. Next line contains N space separated integers a0aN1 denoting array A .

OUTPUT

Output a single line containing the number of pairs as described in problem statement.

CONSTRAINTS

  • 1N106
  • 1D106
  • 1ai109
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

You can take number at index 4 (1 based indexing) with any of other 6 numbers. Their product will be divisible by D i.e. 7. No other pair will give product divisible by D.

Editor Image

?