Rust: use k's divisors
Complexity\n- Time complexity: O(n * y), where y is number of divisors k has.\n\n- Space complexity: O(k)\n\n# Code\n\nimpl Solution {\n    pub fn count_pairs(n
# Complexity\n- Time complexity: $$O(n * y)$$, where $$y$$ is number of divisors `k` has.\n\n- Space complexity: $$O(k)$$\n\n# Code\n```\nimpl Solution {\n    pub fn count_pairs(nums: Vec<i32>, k: i32) -> i64 {\n        let k = k as usize;\n        let divisors = Self::get_divisors(k);\n        let mut count = vec![0i64; k + 1];\n        let mut ans = 0i64;\n        for x in nums.iter().map(|&x| x as usize) {\n            let mut divided = false;\n            for &y in divisors.iter() {\n                if x % y == 0 {\n                    if !divided {\n                        ans += count[k / y];\n                        divided = true;\n                    }\n                    count[y] += 1;\n                }\n            }\n        }\n        ans\n    }\n\n    fn get_divisors(k: usize) -> Vec<usize> {\n        let mut divisors = vec![1usize];\n        let mut divisors2 = vec![k];\n        for i in 2..k {\n            if i * i > k {\n                break;\n            }\n            if k % i == 0 {\n                divisors.push(i);\n                divisors2.push(k / i);\n            }\n        }\n        if divisors.last().unwrap() == divisors2.last().unwrap() {\n            divisors.pop();\n        }\n        divisors.reverse();\n        divisors2.append(&mut divisors);\n        divisors2\n    }\n}\n```
['Math', 'Rust']