-
Notifications
You must be signed in to change notification settings - Fork 0
/
divisible_sum_pairs.py
138 lines (133 loc) · 2.3 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""
The function is expected to return an INTEGER.
The function accepts following parameters:
1. INTEGER n
2. INTEGER k
3. INTEGER_ARRAY ar
"""
def divisibleSumPairs(n, k, ar):
"""Count number of divisible sum pair from given array.
Args:
n (int): No of items in list.
k (int): Sum to check.
ar (list): List of numbers
Returns:
_type_: _description_
"""
count = 0
for i in range(n):
for j in range(n):
if (i < j) and (ar[i] + ar[j]) % k == 0:
count += 1
return count
# succesfull output 3
print(divisibleSumPairs(6, 5, [1, 2, 3, 4, 5, 6, 5]))
# succesfull output 216
print(
divisibleSumPairs(
100,
22,
[
43,
95,
51,
55,
40,
86,
65,
81,
51,
20,
47,
50,
65,
53,
23,
78,
75,
75,
47,
73,
25,
27,
14,
8,
26,
58,
95,
28,
3,
23,
48,
69,
26,
3,
73,
52,
34,
7,
40,
33,
56,
98,
71,
29,
70,
71,
28,
12,
18,
49,
19,
25,
2,
18,
15,
41,
51,
42,
46,
19,
98,
56,
54,
98,
72,
25,
16,
49,
34,
99,
48,
93,
64,
44,
50,
91,
44,
17,
63,
27,
3,
65,
75,
19,
68,
30,
43,
37,
72,
54,
82,
92,
37,
52,
72,
62,
3,
88,
82,
71,
],
)
)