-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDivisible Sum Pairs.py
88 lines (46 loc) · 1.63 KB
/
Divisible Sum Pairs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/python3
import math
import os
import random
import re
import sys
from itertools import combinations
# Complete the divisibleSumPairs function below.
def divisibleSumPairs(n, k, ar):
count = 0
list1 = [i for i in range(n)]
list1 = list(combinations(list1,2))
for i,j in list1:
if i < j and (ar[i]+ar[j])%k == 0:
count += 1
return count
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nk = input().split()
n = int(nk[0])
k = int(nk[1])
ar = list(map(int, input().rstrip().split()))
result = divisibleSumPairs(n, k, ar)
fptr.write(str(result) + '\n')
fptr.close()
# You are given an array of integers, , and a positive integer, . Find and print the number of pairs where and + is divisible by .
# For example, and . Our three pairs meeting the criteria are and .
# Function Description
# Complete the divisibleSumPairs function in the editor below. It should return the integer count of pairs meeting the criteria.
# 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, and .
# The second line contains space-separated integers describing the values of .
# Constraints
# Output Format
# Print the number of pairs where and + is evenly divisible by .
# Sample Input
# 6 3
# 1 3 2 6 1 2
# Sample Output
# 5
# Explanation
# Here are the valid pairs when :