Skip to content

Instantly share code, notes, and snippets.

@r6m
Last active April 15, 2018 21:17
Show Gist options
  • Save r6m/93ec72226b928061f71f3fbe1e96a2d0 to your computer and use it in GitHub Desktop.
Save r6m/93ec72226b928061f71f3fbe1e96a2d0 to your computer and use it in GitHub Desktop.
find integer with most divisors
my_list = [int(i) for i in input().split(' ')] # get items from input with spaces between
def find_integer_with_most_divisors(input_list):
num, div = 0, 0 # tmp
for item in my_list: # iterate list
div_count = 0
for i in range(1, item + 1): # genrate numbers
if item % i == 0: # check divisor
div_count += 1
if div_count > div:
num, div = item, div_count
# print(num, div)
return num
num = find_integer_with_most_divisors(my_list)
print(num)
# there might be better solutions. this one just pop in my mind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment