2176. Count Equal and Divisible Pairs in an Array Easy
1/**
2 * [2176] Count Equal and Divisible Pairs in an Array
3 *
4 * Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < j < n, such that nums[i] == nums[j] and (i * j) is divisible by k.
5 *
6 * Example 1:
7 *
8 * Input: nums = [3,1,2,2,2,1,3], k = 2
9 * Output: 4
10 * Explanation:
11 * There are 4 pairs that meet all the requirements:
12 * - nums[0] == nums[6], and 0 * 6 == 0, which is divisible by 2.
13 * - nums[2] == nums[3], and 2 * 3 == 6, which is divisible by 2.
14 * - nums[2] == nums[4], and 2 * 4 == 8, which is divisible by 2.
15 * - nums[3] == nums[4], and 3 * 4 == 12, which is divisible by 2.
16 *
17 * Example 2:
18 *
19 * Input: nums = [1,2,3,4], k = 1
20 * Output: 0
21 * Explanation: Since no value in nums is repeated, there are no pairs (i,j) that meet all the requirements.
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= nums.length <= 100
27 * 1 <= nums[i], k <= 100
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array/
33// discuss: https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn count_pairs(nums: Vec<i32>, k: i32) -> i32 {
39 0
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_2176() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.