![]() |
VOOZH | about |
Given a number N, the task is to find the sum of all even factors of that number. A factor of a number divides it completely without leaving a remainder, and even factors are those divisible by 2. For Example:
Input: 30
Output: 48
Even factors: 2 + 6 + 10 + 30 = 48
Let’s explore different Python methods to find the sum of even factors efficiently.
This method uses prime factorization and the sum of divisors formula to directly compute the sum of even factors. If the number is even, it ignores the odd part and multiplies only the even factor contributions to get the sum efficiently.
26
Explanation:
This method uses Python’s list comprehension to collect all even factors in one line, then sums them using sum().
26
Explanation:
This method first finds all factors of the number, then filters only even ones using a lambda function and filter().
26
Explanation: filter(lambda x: x % 2 == 0, fac) keeps only even factors and sum() calculates the total sum of filtered even factors.
This method converts numbers to strings and back using list comprehensions and enumerate, though less efficient, it still achieves the result cleanly.
26
Explanation: Converts numbers to strings for iteration (str(i)), then back to int(i) for divisibility checks. Filters even factors and sums them up.
Please refer complete article on Find sum of even factors of a number for more details!