• + 4 comments

    If anyone is interested here is more modern and clear way of doing the same thing.

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    int main() 
    {
    	int n, k;
    
    	cin >> n >> k;
    
    	vector<int> complenemts(k);
    
    	int count = 0;
    
    	int temp;
    	for (int i = 0; i < n; ++i)
    	{
    		cin >> temp;
    
    		int remainder = (temp % k);
    
    		int complenemt = (k - remainder) % k;
    
    		count += complenemts[remainder];
    
    		complenemts[complenemt] += 1;
    	}
    
    	cout << count;
    
    	return 0;
    }