- Related Questions & Answers
- C++ Program to find sum of even factors of a number?
- Java Program to Find sum of even factors of a number
- Find sum of even factors of a number using C++.
- Find sum of even factors of a number in Python Program
- Python Program for Find sum of even factors of a number
- C Program for Find sum of odd factors of a number?
- C++ program for Find sum of odd factors of a number
- C Program to Find the minimum sum of factors of a number?
- Java Program to find minimum sum of factors of a number
- Find sum of odd factors of a number using C++.
- Python Program for Find sum of odd factors of a number
- Find minimum sum of factors of number using C++.
- Python Program for Find minimum sum of factors of number
- C/C++ Program to find Product of unique prime factors of a number?
- Find number of subarrays with even sum in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

This program is used to find all the even factors and calculate the sum of these even factors and display it as output.

Example −

Input : 30 Even dividers : 2+6+10+30 = 48 Output : 48

For this, we will find all the factors. Find the even of them and find the sum,

Else, we will use the formula to find the sum of factors using the prime factors,

Sum of divisors = (1 + d_{1}^{1}+ d_{1}^{2}... d_{1}^{a1}) *(1 + d_{2}^{1}+ d_{2}^{2}... d_{2}^{a2}) *...........................* (1 + d_{k}^{1}+ d_{k}^{2}... d_{k}^{ak}) Here di = prime factors ; ai = power of di

We need only even factors so, if the number is odd then no even factor exists. So, we will output 0 in that case.

#include <iostream> #include <math.h> using namespace std; int main() { int n=12; int m = n; if (n % 2 != 0) cout<<"The sum of all even factors of " << n <<" is "<<0; int evfac = 1; for (int i = 2; i <= sqrt(n); i++) { int count = 0, curr_sum = 1, curr_term = 1; while (n % i == 0) { count++; n = n / i; if (i == 2 && count == 1) curr_sum = 0; curr_term *= i; curr_sum += curr_term; } evfac *= curr_sum; } if (n >= 2) evfac *= (1 + n); cout <<"The sum of all even factors of " << m <>" is "<>evfac; return 0; }

The sum of all even factors of 12 is 24

Advertisements