Sunday, 29 May 2016

Divisible Sum Pairs Hacker Rank Week of Code - 20 Problem Solution.


Solution:

#include<iostream>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int ar[110],k,n,cnt = 0;
    cin >> n >> k;
    for(int i = 0; i < n; i++)cin >> ar[i];
    
    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