Skip to content

Instantly share code, notes, and snippets.

@esthicodes
Created August 24, 2021 01:02
Show Gist options
  • Save esthicodes/eea75db8df27e602681f98c8a9ddc1ac to your computer and use it in GitHub Desktop.
Save esthicodes/eea75db8df27e602681f98c8a9ddc1ac to your computer and use it in GitHub Desktop.
hackerrank
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<assert.h>
#include<limits.h>
#include<stdbool.h>
int main ()
{
int n;
int k;
scanf("%d %d",&n,&k);
int *a = malloc(sizeof(int) * n);
for(int a_i = 0; a_i < n; a_i++){
scanf("%d",&a[a_i]);
}
int sum = 0;
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if ( (a[i]+a[j])%k == 0)
sum++;
}
}
printf("%d\n",sum);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment