Ejemplo n.º 1
0
def get_sum_divisors(num=0):
    # TODO: Explain combinatorically
    if num == 0 or num == 1:
        return num
    total_sum = 1
    for p, num_primes in prime.get_prime_factorization(num=num).items():
        current_sum = 0
        for i in range(num_primes + 1):
            current_sum += p**i
        total_sum *= current_sum
    return total_sum
Ejemplo n.º 2
0
def get_sum_divisors(num=0):
    # TODO: Explain combinatorically
    if num == 0 or num == 1:
        return num
    total_sum = 1
    for p, num_primes in prime.get_prime_factorization(num=num).items():
        current_sum = 0
        for i in range(num_primes + 1):
            current_sum += p**i
        total_sum *= current_sum
    return total_sum
Ejemplo n.º 3
0
def run_problem(num_divisors=500):
    n = 3
    prime_factorization_1 = prime.get_prime_factorization(2)
    prime_factorization_2 = prime.get_prime_factorization(3)
    curr_num_divisors = _get_curr_num_divisors(
        factorizations=[
            prime_factorization_1,
            prime_factorization_2,
        ],
    )
    while curr_num_divisors < num_divisors:
        n += 1
        prime_factorization_1 = prime_factorization_2
        prime_factorization_2 = prime.get_prime_factorization(n)
        curr_num_divisors = _get_curr_num_divisors(
            factorizations=[
                prime_factorization_1,
                prime_factorization_2,
            ],
        )
    return int(n * (n - 1) / 2)
Ejemplo n.º 4
0
def get_num_divisors(num=0):
    # TODO: Explain combinatorically
    total_divisors = 1
    for x in prime.get_prime_factorization(num=num).values():
        total_divisors *= x + 1
    return total_divisors
Ejemplo n.º 5
0
def get_num_divisors(num=0):
    # TODO: Explain combinatorically
    total_divisors = 1
    for x in prime.get_prime_factorization(num=num).values():
        total_divisors *= x + 1
    return total_divisors
Ejemplo n.º 6
0
 def test_error_case(self):
     # Given a number with no prime factorization
     # Then we should get a ValueError
     with pytest.raises(ValueError):
         # When we try to get its prime factorization
         prime.get_prime_factorization(1)
Ejemplo n.º 7
0
 def test_non_error_cases(self, num, expected):
     # Given a <num> bigger than one
     # When we get its prime factorization
     result = prime.get_prime_factorization(num)
     # Then the result should be <expected>
     assert result == expected
Ejemplo n.º 8
0
def run_problem(num=600851475143):
    return max(prime.get_prime_factorization(num))
Ejemplo n.º 9
0
 def test_error_case(self):
     # Given a number with no prime factorization
     # Then we should get a ValueError
     with pytest.raises(ValueError):
         # When we try to get its prime factorization
         prime.get_prime_factorization(1)
Ejemplo n.º 10
0
 def test_non_error_cases(self, num, expected):
     # Given a <num> bigger than one
     # When we get its prime factorization
     result = prime.get_prime_factorization(num)
     # Then the result should be <expected>
     assert result == expected