Skip to content

Instantly share code, notes, and snippets.

@lucasamparo
Last active February 26, 2019 13:48
Show Gist options
  • Save lucasamparo/c435921036806e0b7698f99422e3bfd2 to your computer and use it in GitHub Desktop.
Save lucasamparo/c435921036806e0b7698f99422e3bfd2 to your computer and use it in GitHub Desktop.
A code snippet to pick the set of divisor from a number, with or without limit the largest possible value. Enjoy, if useful.
import numpy as np
def pick_divisors(value, max_divisor=None):
divisors = []
calc_value = np.int0(np.sqrt(value))
limit = calc_value if max_divisor is None else min(max_divisor, calc_value)
for i in range(1, limit):
if value % i == 0:
divisors.append(i)
return divisors
print(pick_divisors(1000, 100))
print(pick_divisors(129030198, 2000))
print(pick_divisors(1349586))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment