from tools import number_theory def find_a_factor(num, prime): while prime: p = prime.pop(0) if not (num % p): return p, prime return 0, [] def factor_num(num): prime = list(number_theory.make_prime(int(num ** 0.5))) factors = [] while True: factor, prime = find_a_factor(num, prime) if factor: factors.append(factor) while not (num % factor): num //= factor else: if 1 != num: factors.append(num) return factors print(factor_num(600851475143))