Monday, 3 April 2017

Hacker Rank Solution For " Divisible Sum Pairs " in C++

Problem :- Divisible Sum Pairs

Submit Your Solution Here :- Click Here

Copy The Code and paste it into hackerrank Editor .

Solution :-

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    int k;
    int c=0;
    cin >> n >> k;
    vector<int> a(n);
    for(int a_i = 0;a_i < n;a_i++){
       cin >> a[a_i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i<j)
            {
                if((a[i]+a[j])%k==0)
                    c++;
            }
        }
    }
    cout<<c;
    return 0;
}

Output :-

Hacker Rank Solution For " Divisible Sum Pairs " in C++



No comments:
Write comments

Recommended Posts × +