Counting Triplets
There is an integer array arr[n] and an integer value d. The array is indexed from 1 to n.
Count the number of distinct triplets (i, j, k) such that 0 < i < j < k ≤ n and the sum (a[i] + a[j] + a[k]) is divisible by d.
Example
a = [3, 3, 4, 7, 8]
d = 5
The following triplets are divisible by d = 5.
Following are the triplets whose sum is divisible by d (1-based indexing):
- indices (1, 2, 3), sum = 3 + 3 + 4 = 10
- indices (1, 3, 5), sum = 3 + 4 + 8 = 15
- indices (2, 3, 4), sum = 3 + 4 + 8 = 15
Since there is no other triplet divisible by d = 5, the output is the count of these triplets.
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.