Skip to content

Commit

Permalink
Divisible Sum Pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
rmres committed Oct 20, 2020
1 parent ef6bccb commit 925506f
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions divisiblesumpairs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;

class Solution {

// Complete the divisibleSumPairs function below.
static int divisibleSumPairs(int n, int k, int[] ar) {
int count = 0;

for (int i = 0; i < ar.Length; i++) {
for (int j = 0; j < ar.Length; j++) {
if (i < j && (ar[i] + ar[j]) % k == 0) {
count++;
}
}
}
return count;
}

static void Main(string[] args) {
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);

string[] nk = Console.ReadLine().Split(' ');

int n = Convert.ToInt32(nk[0]);

int k = Convert.ToInt32(nk[1]);

int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp))
;
int result = divisibleSumPairs(n, k, ar);

textWriter.WriteLine(result);

textWriter.Flush();
textWriter.Close();
}
}

0 comments on commit 925506f

Please sign in to comment.