Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create Divisible Sum Pairs.js
  • Loading branch information
Anna-Myzukina committed Mar 27, 2020
1 parent b22a2e9 commit 539aec5
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Divisible Sum Pairs.js
@@ -0,0 +1,57 @@
'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});

process.stdin.on('end', _ => {
inputString = inputString.replace(/\s*$/, '')
.split('\n')
.map(str => str.replace(/\s*$/, ''));

main();
});

function readLine() {
return inputString[currentLine++];
}

// Complete the divisibleSumPairs function below.
function divisibleSumPairs(n, k, ar) {

var count = 0;
for(var i = 0; i < n; i++) {
for(var j = i+1; j < n; j++) {
if((ar[i] + ar[j]) % k === 0) {
count++;
}
}
}
return count;
}

function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

const nk = readLine().split(' ');

const n = parseInt(nk[0], 10);

const k = parseInt(nk[1], 10);

const ar = readLine().split(' ').map(arTemp => parseInt(arTemp, 10));

let result = divisibleSumPairs(n, k, ar);

ws.write(result + "\n");

ws.end();
}

0 comments on commit 539aec5

Please sign in to comment.