• + 0 comments
    public static int divisibleSumPairs(int n, int k, List<Integer> ar) {
            Map<Integer, Integer> remainderCounts=new HashMap<>();
            long count=0;
    
            for (int i=0; i<n; i++)
            {
                int rem1=ar.get(i) % k;
                if (rem1!=0)
                    count+=remainderCounts.getOrDefault(k-rem1, 0);
                else
                    count+=remainderCounts.getOrDefault(0, 0);
    
                remainderCounts.put(rem1, remainderCounts.getOrDefault(rem1, 0)+1);
            }
    
            return (int) count;
        }