“Division Pair Sum”
where i < j and ar[i]+ar[j] is divisible by k .
For example, ar=[1,2,3,4,5,6] and k=5 . Our three pairs meeting the criteria are [1,4],[2,3] and [4,6].
Function Description
divisibleSumPairs has the following parameter(s):
• n: the integer length of array
• ar: an array of integers
• k: the integer to divide the pair sum by
Input Format
The first line contains space-separated integers, n and k. The second line contains space-separated n integers describing the values of .ar.
Output Format
Print the number of pairs where and ar[i]+ar[j] is evenly divisible by k .
Sample Input
6 3
1 3 2 6 1 2
Sample Output
5
Explanation
Here are the 5 valid pairs when k=3 :
Click here to Subscribe Intellective Tech for Coding and Campus Preparation
• (0,2) -> ar[0]+ar[2] = 1+2 =3
• (0,5) -> ar[0]+ar[5] = 1+2 =3
• (1,3) -> ar[1]+ar[3] = 3+6 = 9
• (2,4) -> ar[2]+ar[4] = 2+1 =3
• (4,5) -> ar[4]+ar[5] = 1+2 =3
No comments:
Post a Comment