MathWorksOA #1
Counting Triplets (Sum Divisible by d)
Estimated MediumJudge-ready
Topics (AI-labelled)HashingBits & Math
Given an integer array, count the triplets with strictly increasing indices whose three values sum to a multiple of d.
This site uses a standard input/output protocol.
Input
The first line contains n d; the second line contains n integers. 3≤n≤1000, 1≤arr[i]≤10^9, 2≤d≤10^6.
Output
Output the number of qualifying index triplets.
Example 1
Input:
4 3
2 3 1 6
Output:
2
Example 2
Input:
3 3
1 1 1
Output:
1
Example 3
Input:
4 5
1 2 4 8
Output:
0
Editorial
Loading solution…