← 返回 sofi 的题目列表Count Triplets with Sum Divisible by d in Array
类型:online_judge
sofi
Given an array arr and an integer d, find out how many triplets (i, j, k) satisfy 0 <= i < j < k < len(arr) and arr[i] + arr[j] + arr[k] is divisible by d. n (the length of the array) does not exceed 10^3.
Example
Input: arr = [1, 2, 3, 4, 5, 6], d = 3 Output: 2
Input: arr = [2, 2, 2, 2], d = 2 Output: 4
Constraints
n <= 10^3
arr[i] is a non-negative integer
d is a positive integer
Example
Input
1 2 3 4 5 6
3