Here another small snippet of mathematical nature returning all possible divisors of number.
(set is, by the way, needed because of perfect squares
Not possible to edit the snippet part but here the same with less stupid command line interface (not repeating the loop):
def divides(n):
return sorted(set(sum( ([x,n/x] for x in range(1, int(n**0.5+0.5) + 1) if not n%x), [] )))
if __name__ =='__main__':
import sys
sequence = map(int, sys.argv[1:]) if sys.argv[1:] else (45, 53, 64,1231435)
for number in sequence:
print( "%s divides %i " %
(', '.join(map(str, divides(number))), number) )
Without set:
def divides(n):
return sorted(sum( ([x,n/x] if x*x != n else [x] for x in range(1, int(n**0.5+0.5) + 1) if not n%x), [] ))
if __name__ =='__main__':
import sys
sequence = map(int, sys.argv[1:]) if sys.argv[1:] else (45, 53, 64,1231435)
for number in sequence:
print( "%s divides %i " %
(', '.join(map(str, divides(number))), number) )