Skip to content

Commit 2acc353

Browse files
author
emtiazzahid
committed
solved divisible-sum-pairs
1 parent 5d2f2e9 commit 2acc353

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

OUTPUT_PATH.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4 0
1+
5

divisible-sum-pairs.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
// Complete the divisibleSumPairs function below.
4+
function divisibleSumPairs($n, $k, $ar) {
5+
$c = 0;
6+
for ($i = 0; $i < $n ; $i++)
7+
{
8+
for ($j = $i+1; $j < $n; $j++)
9+
{
10+
if ((($ar[$i]+$ar[$j]) % $k) == 0)
11+
{
12+
$c++;
13+
}
14+
}
15+
}
16+
return $c;
17+
}
18+
19+
$fptr = fopen("OUTPUT_PATH.txt", "w");
20+
21+
$stdin = fopen("php://stdin", "r");
22+
23+
fscanf($stdin, "%[^\n]", $nk_temp);
24+
$nk = explode(' ', $nk_temp);
25+
26+
$n = intval($nk[0]);
27+
28+
$k = intval($nk[1]);
29+
30+
fscanf($stdin, "%[^\n]", $ar_temp);
31+
32+
$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));
33+
34+
$result = divisibleSumPairs($n, $k, $ar);
35+
36+
fwrite($fptr, $result . "\n");
37+
38+
fclose($stdin);
39+
fclose($fptr);

0 commit comments

Comments
 (0)