هک‌ها و تشعشعات وجدان آزاد

نوشته‌های سیدمحمدمسعود صدرنژاد

ابزار کاربر

ابزار سایت


courseware:python_programming:resources:answer:18

پاسخ پرسش اعداد جالب

import math
 
def find_interesting_numbers(n):
    number = 8
    interesting_numbers = list()
    while len(interesting_numbers) < n:
        current_number = number
        factors = 0
        while current_number % 2 == 0:  # count all even factors
            factors += 1
            current_number //= 2
        for i in range(3, int(math.sqrt(current_number)) + 1, 2):   # count all odd factors
            while current_number % i == 0:
                factors += 1
                current_number //= i
        if current_number != 1:   # check if the remainder number is a prime number by itself
            factors += 1
        if factors == 3:
            interesting_numbers.append(number)
        number += 1
    return interesting_numbers
courseware/python_programming/resources/answer/18.txt · آخرین ویرایش: 2020/09/15 15:46 (ویرایش خارجی)