Solution of 'Divisible Sum Pairs' (HackerRank)

Hi all!
Here's my solution to the problem 'Divisible Sum Pairs' from HackerRank.

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;

int divisibleSumPairs(int n, int k, vector<int> ar) {
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if((ar[i]+ar[j])%k==0) cnt++;
        }
    }
    return cnt;
}

int32_t main()
{
    int n,k;
    cin>>n>>k;
    vector<int> num;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        num.pb(x);
    }
    int res= divisibleSumPairs(n,k,num);
    cout<<res;
}

Comments

Popular posts from this blog

Solution of 'The Two Dishes' (Codechef)

Solution of 'Tom Riddle's Diary' (Codeforces)

Solution to the problem 'Red Light, Green Light' from Codechef