Sunday, 3 July 2016

Divisible Sum Pairs Hacker Rank Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int n,k,a,cnt = 0;
    vector<int>ar;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> a;
        ar.push_back(a);
    }
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if((ar[i]+ar[j])%k == 0){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

No comments:

Post a Comment