Store the input sequence of numbers in an array.
Let . Then iterate over all pairs with i < j. If a_i + a_j is divisible by , increase by .
Algorithm implementation
Declare an array .
#define MAX 101
int m[MAX];Read the input data.
scanf("%d %d", &n, &k);
for (i = 0; i < n; i++)
scanf("%d", &m[i]);The variable stores the number of required pairs.
res = 0;Iterate over all pairs with i < j. If a_i + a_j is divisible by , increase by .
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if ((m[i] + m[j]) % k == 0) res++;Print the answer.
printf("%d\n", res);