We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Divisible Sum Pairs
  5. Discussions

Divisible Sum Pairs

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 2158 Discussions, By:

recency

Please Login in order to post a comment

  • ayushkumarroy
    1 day ago+ 0 comments
    def divisibleSumPairs(n, k, ar):
        count = 0
        for i in range(n):
            for j in range(i+1,n):
                if (ar[i]+ar[j]) % k == 0:
                    count+=1
        return count
    
    0|
    Permalink
  • sharp_thinker
    7 days ago+ 0 comments

    C++ Code here

    include

    using namespace std;

    int main (){

    int n, k, count = 0;
    cin >> n >> k;
    int array[n];
    for (int i = 0; i < n; i++){
        cin >> array[i];
    }
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            if ((array[i] + array[j]) % k == 0){
                count++;
            }
        }
    }
    
    cout << count;
    
    return 0;
    

    }

    0|
    Permalink
  • idttalbe_m
    1 week ago+ 0 comments
    Python 3 solution
    def divisibleSumPairs(n, k, ar):
        # Write your code here
        couple = [sum([ar[i],ar[j]])%k == 0 for i in range(n) for j in range(i+1,n) ]
        return(sum(couple))
    
    0|
    Permalink
  • anurag_jain5
    1 week ago+ 0 comments

    PHP :

    function divisibleSumPairs($n, $k, $ar) {
        // Write your code here
        $count = 0;
        for($i = 0; $i < $n; $i++){
            for($j = $i+1; $j < $n; $j++){
                if(($ar[$i]+$ar[$j]) % $k == 0)
                    $count++;
            }
        }
        return $count;
    }
    
    0|
    Permalink
  • MrCyberlord
    2 weeks ago+ 0 comments

    Easy JavaScript Solution

    let counter = 0
    
    for(var i=0;i<n-1;i++)
    {
        for(var j=i+1;j<n;j++)
        {
            if((ar[i]+ar[j])%k==0)
            {
            counter++
            }
        }
    }
    
    return counter
    

    Please upvote if you like the solution

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy