0 out of 464 challenges solved
Write a Python function `sum_of_common_divisors(a, b)` that calculates the sum of all common divisors of two given positive integers `a` and `b`. A divisor of a number is an integer that divides the number without leaving a remainder. For example, the divisors of 10 are 1, 2, 5, and 10. #### Example Usage ```python [main.nopy] print(sum_of_common_divisors(10, 15)) # Output: 6 (common divisors: 1, 5) print(sum_of_common_divisors(100, 150)) # Output: 93 (common divisors: 1, 2, 5, 10, 25, 50) print(sum_of_common_divisors(4, 6)) # Output: 3 (common divisors: 1, 2) ```
def sum_of_common_divisors(a, b): """ Calculate the sum of all common divisors of two given positive integers a and b. Args: a (int): The first positive integer. b (int): The second positive integer. Returns: int: The sum of all common divisors of a and b. """ # Initialize the sum of common divisors total = 0 # Iterate through possible divisors # Placeholder for the solution return total