0 out of 464 challenges solved
Write a Python function `is_sum_of_powers_of_two(n)` that determines whether a given positive integer `n` can be represented as the sum of distinct non-zero powers of 2. A number can be expressed as such a sum if it can be written as a sum of terms like `2^0`, `2^1`, `2^2`, etc., without repeating any power. #### Example Usage ```python [main.nopy] print(is_sum_of_powers_of_two(10)) # True, because 10 = 2^3 + 2^1 print(is_sum_of_powers_of_two(7)) # True, because 7 = 2^2 + 2^1 + 2^0 print(is_sum_of_powers_of_two(14)) # True, because 14 = 2^3 + 2^2 + 2^1 print(is_sum_of_powers_of_two(0)) # False, as 0 cannot be expressed as a sum of non-zero powers of 2 ``` #### Constraints - The input `n` will be a non-negative integer. - The function should return `True` if the number can be expressed as a sum of distinct non-zero powers of 2, and `False` otherwise.
def is_sum_of_powers_of_two(n): """ Determine if the given number can be represented as a sum of distinct non-zero powers of 2. Args: n (int): The number to check. Returns: bool: True if the number can be represented as a sum of distinct non-zero powers of 2, False otherwise. """ # Placeholder for the solution pass