Created
March 12, 2022 16:15
-
-
Save igorvanloo/42d7aa776fc28aac2459fbf6a1b88e3a to your computer and use it in GitHub Desktop.
k_smooth_numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def k_smooth_numbers(max_prime, limit): | |
k_s_n = [1] | |
p = list_primes(max_prime) | |
while len(p) != 0: | |
temp_k_s_n = [] | |
curr_p = p.pop(0) | |
power_limit = int(math.log(limit, curr_p)) + 1 | |
curr_multiples = [curr_p**x for x in range(1, power_limit + 1)] | |
for x in curr_multiples: | |
for y in k_s_n: | |
temp = x*y | |
if temp <= limit: | |
temp_k_s_n.append(temp) | |
k_s_n += temp_k_s_n | |
return len(k_s_n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment