N
N
nepp2020-12-01 21:23:46
Arrays
nepp, 2020-12-01 21:23:46

An algorithm that would search in an array of numbers for those from the sum of which you can get a given number?

How can it be implemented?

For example, number: 12
Array of numbers: 6 2 4 9 11 3

Output: 6 2 4
If there are several combinations, outputs any

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Siomin, 2020-12-01
@nepp

num = int(input())
numList = []
while True:
    num2 = input()
    if num2 != '':
        numList.append(int(num2))
    else:
        break
    

numList2 = []
for elem in numList:
    if num%elem == 0:
        numList2.append(elem)

for elem in numList2:
    print(elem)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question