
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Aliquot sum in C++?
Here we will see what is the Aliquot sum? The Aliquot sum of n is the sum of all perfect factors of a n except the n. For example, if the number is 20, then the perfect factors are (1, 2, 4, 5, 10). So the Aliquot sum is 22.
One interesting fact is that, if Aliquot sum of a number is the number itself, then that number is a perfect number. For example, 6. The factors are (1, 2, 3). The Aliquot sum is 1+2+3=6.
Let us see how we can get the Aliquot sum using the following algorithm.
Algorithm
getAliquotSum(n)
begin sum := 0 for i in range 1 to n, do if n is divisible by i, then sum := sum + i end if done return sum. end
Example
#include <iostream> using namespace std; int getAliquotSum(int n) { int sum = 0; for(int i = 1; i<n; i++) { if(n %i ==0) { sum += i; } } return sum; } int main() { int n; cout << "Enter a number to get Aliquot sum: "; cin >> n; cout << "The Aliquot sum of " << n << " is " << getAliquotSum(n); }
Output
Enter a number to get Aliquot sum: 20 The Aliquot sum of 20 is 22
- Related Articles
- Aliquot Sequence in C++
- Count of numbers satisfying m + sum(m) + sum(sum(m)) = N in C++
- Maximum subarray sum in O(n) using prefix sum in C++
- Sum of sum of first n natural numbers in C++
- Find sum of sum of all sub-sequences in C++
- Construct sum-array with sum of elements in given range in C++
- Target Sum in C++
- Combination Sum in Python
- Two Sum in Python
- Path Sum in Python
- sum() function in Python
- Count rows/columns with sum equals to diagonal sum in C++
- Find maximum sum possible equal sum of three stacks in C++
- Difference between sum of square and square of sum in JavaScript
- Sum of XOR of sum of all pairs in an array in C++

Advertisements