from math import sqrt def decomp(n): k = 2 c, p = [], [] u = n while k <= n: i = 0 while u % k == 0: i += 1 u //= k if i > 0: c.append(k) p.append(i) k += 1 return c, p def prod(arr): r = 1 for x in arr: r *= x return r def idivis(n): coeff, puiss = decomp(n) puiss = [v + 1 for v in puiss] p = prod(puiss) div = [] for k in range(p): u = k r = 1 for (i, v) in enumerate(puiss): r *= coeff[i] ** (u % v) u //= v div.append(r) return div print(idivis(36)) print(idivis(360)) print(idivis(1000))