Cerinta completa
Given an array of integers and a positive integer , determine the number of pairs where and + is divisible by .
Example
Three pairs meet the criteria: and .
Function Description
Complete the divisibleSumPairs function in the editor below.
divisibleSumPairs has the following parameter(s):
- int n: the length of array
- int ar[n]: an array of integers
- int k: the integer divisor
Returns
– int: the number of pairs
Input Format
The first line contains space-separated integers, and .
The second line contains space-separated integers, each a value of .
Constraints
Sample Input
STDIN Function
----- --------
6 3 n = 6, k = 3
1 3 2 6 1 2 ar = [1, 3, 2, 6, 1, 2]
Sample Output
5
Explanation
Here are the valid pairs when :
Limbajul de programare folosit: python3
Cod:
import sys
data = list(map(int, sys.stdin.read().strip().split()))
n, k = data[0], data[1]
arr = data[2:2+n]
mods = [0]*k
count = 0
for x in arr:
r = x % k
count += mods[(k-r) % k]
mods[r] += 1
print(count)
Scor obtinut: 1.0
Submission ID: 464552566
Link challenge: https://www.hackerrank.com/challenges/divisible-sum-pairs/problem
