values and a number divisor. Count the triples of indices (i, j, k) with i < j < k for which values[i] + values[j] + values[k] is divisible by divisor.
Triples are told apart by their indices: equal values at different positions make different triples.values=[2, 5, 1, 4, 3], divisor=6 → 2
Two triples work: indices (0, 2, 4) with 2 + 1 + 3 = 6, and (1, 3, 4) with 5 + 4 + 3 = 12. None of the other eight sums is divisible by 6.
values=[6, 6, 6, 6], divisor=4 → 0
Every triple sums to 18, which is not divisible by 4.
values=[5, 10, 15, 20], divisor=5 → 4
Every number is a multiple of 5, so all 4 triples qualify.
values.length ≤ 1000values[i] ≤ 10⁹divisor ≤ 10⁹values=[2, 5, 1, 4, 3], divisor=6
2
Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.