You are here : InfyTQ Archive >> InfyTQ Coding Problems
For a given list of numbers, find its factors and add the factors. Then if the sum of factors is present in the original list, sort it and print it else print -1.
Input :
First Input : List of numbers
Output : List of factors
Sample Testcases :
I/P 1:
1,2,4,7
O/P 1:
[1,4]
I/P 2:
2,4
O/P 2:
-1
Solution :
def findfactsum(n):
s=1
for j in range(2,n+1):
if n%j==0:
s+=j
return s
res=[]
l=list(map(int,input()))
for i in l:
val=findfactsum(i)
if val in l:
res.append(i)
if(len(res)==0):
print(“-1”)
else:
print(sorted(res))