Divisible Sum Pairs

  • + 0 comments

    A naive rust approach:

    fn divisibleSumPairs(n: i32, k: i32, ar: &[i32]) -> i32 {
        let mut x = 1;
        let mut n_pairs = 0;
        
        for &i in ar {
            for &j in &ar[x..] {
                if (i + j) % k == 0 {
                    n_pairs += 1;
                }
            }
            x += 1;
        }
        n_pairs
    }