def smallest_continuous_multiple(max_multiple):
    """
    Function takes an int, and returns the smallest natural number evenly divisible by all numbers
    less than or equal to the input max_multiple.

    REQ: max_multiple >= 0 and whole

    :param max_multiple: {int}
    :return: smallest natural number evenly divisible by all number less than or equal to input

    Function reduces time complexity by iteratively removing redundant factors from the
    check_list, ie. suppose 12 exists in the list, then 6, 4, 3, 2 and 1 will have been removed.
    This check is done to remove the factors of every int, to reduce the lookup time later.
    """

    # all numbers less than or equal to 2 are evenly divisible by themselves and below
    if max_multiple <= 2:
        return max_multiple

    check_list = []
    # make a list of all ints from 1 to input
    for i in range(max_multiple):
        check_list.append(i + 1)

    # loop through check list backwards
    for i in reversed(check_list):
        # get factors of i without i included
        temp_factors = get_factors(i)
        temp_factors.remove(i)
        # loop through the remaining factors, removing them from the check_list
        for j in temp_factors:
            try:
                check_list.remove(j)
            except ValueError:
                pass

    temp_num = max_multiple
    # loop indefinitely until find smallest int that that satisfies exit condition
    while True:
        # if all factors less than max_multiple divide evenly into curr, return
        if all(temp_num % n == 0 for n in check_list):
            return temp_num
        else:
            temp_num += max_multiple
Ejemplo n.º 2
0
 def test_input_zero(self):
     self.assertEqual(get_factors(0), None)
Ejemplo n.º 3
0
 def test_large_non_prime(self):
     self.assertEqual(get_factors(100), {1, 2, 4, 5, 10, 20, 25, 50, 100})
Ejemplo n.º 4
0
 def test_small_non_prime(self):
     self.assertEqual(get_factors(12), {1, 2, 3, 4, 6, 12})
Ejemplo n.º 5
0
 def test_large_prime(self):
     self.assertEqual(get_factors(97), {1, 97})
Ejemplo n.º 6
0
 def test_small_prime(self):
     self.assertEqual(get_factors(7), {1, 7})
Ejemplo n.º 7
0
 def test_input_one(self):
     self.assertEqual(get_factors(1), {1})