Seongbeom Park 0d75806e4a finish extra/find-the-access-codes
Submitting solution...
Submission: SUCCESSFUL. Completed in: 1 hr, 6 mins, 52 secs.
2022-04-30 03:25:04 +09:00

26 lines
557 B
Python

def solution(l):
nodes = {i: [] for i in range(len(l))}
for i in range(len(l)):
for j in range(i+1, len(l)):
x, y = l[i], l[j]
if y % x == 0:
nodes[i] += [j]
result = 0
for i in nodes:
for j in nodes[i]:
result += len(nodes[j])
return result
tests = [
([1, 1, 1], 1),
([1, 2, 3, 4, 5, 6], 3),
([2, 3, 4], 0),
([1, 1, 2, 3, 4, 5, 6], 11),
]
for i, o in tests:
result = solution(i)
print(i, result == o, result, o)