We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Divisible Sum Pairs
Divisible Sum Pairs
+ 0 comments def divisibleSumPairs(n, k, ar): count = 0 for i in range(n): for j in range(i+1,n): if (ar[i]+ar[j]) % k == 0: count+=1 return count
+ 0 comments C++ Code here
include
using namespace std;
int main (){
int n, k, count = 0; cin >> n >> k; int array[n]; for (int i = 0; i < n; i++){ cin >> array[i]; } for (int i = 0; i < n; i++){ for (int j = i+1; j < n; j++){ if ((array[i] + array[j]) % k == 0){ count++; } } } cout << count; return 0;
}
+ 0 comments Python 3 solutiondef divisibleSumPairs(n, k, ar): # Write your code here couple = [sum([ar[i],ar[j]])%k == 0 for i in range(n) for j in range(i+1,n) ] return(sum(couple))
+ 0 comments PHP :
function divisibleSumPairs($n, $k, $ar) { // Write your code here $count = 0; for($i = 0; $i < $n; $i++){ for($j = $i+1; $j < $n; $j++){ if(($ar[$i]+$ar[$j]) % $k == 0) $count++; } } return $count; }
+ 0 comments Easy JavaScript Solution
let counter = 0 for(var i=0;i<n-1;i++) { for(var j=i+1;j<n;j++) { if((ar[i]+ar[j])%k==0) { counter++ } } } return counter
Please upvote if you like the solution
Load more conversations
Sort 2158 Discussions, By:
Please Login in order to post a comment