
- 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 Sequence in C++
Aliquot sequence is a special sequence of numbers. The sequence starts from the number itself and the next number of the sequence is the sum of the proper divisors of the previous terms.
Let’s take an example of the sequence to learn the concept better −
Input : 8 Output : 8 7 1 0 Explanation : Proper divisors of 8 are 4, 2, 1. The sum is 7 Proper divisors of 7 are 1. The sum is 1 Proper divisors of 1 are 0. The sum is 0
Perfect number is the number that has the aliquot sequence of length one. For example, 6 is a Perfect number.
Amicable number is a number that has aliquot sequence of length two. For example, 1 is an Amicable number.
Sociable number is a number that has aliquot sequence of length three. For example, 7 is a Sociable number.
To calculate the alique sequence from a number. We need to calculate the proper divisors of the term. To calculate this we will use the division algorithm.
Algorithm
Step 1: Initialise the number. Step 2 : Find all the proper divisors of the number. Step 3 : Calculate the sum of all proper divisors. Step 4 : Print the sum and go to step one and initialise number with this sum.
Example
#include <bits/stdc++.h> using namespace std; int Sumfactorial(int n){ int sum = 0; for (int i=1; i<=sqrt(n); i++){ if (n%i==0){ if (n/i == i) sum = sum + i; else{ sum = sum + i; sum = sum + (n / i); } } } return sum - n; } void Aliquotsequence(int n){ printf("%d ", n); unordered_set<int> s; s.insert(n); int next = 0; while (n > 0){ n = Sumfactorial(n); if (s.find(n) != s.end()){ cout << "\nRepeats with " << n; break; } cout << n << " "; s.insert(n); } } int main(){ Aliquotsequence(45); return 0; }
Output
45 33 15 9 4 3 1 0
- Related Articles
- Aliquot sum in C++?
- Permutation Sequence in C++
- Sequence Reconstruction in C++
- Longest Arithmetic Sequence in C++
- Stamping The Sequence in C++
- Baum Sweet Sequence in C Program?
- Convert String into Binary Sequence in C++
- Find maximum length Snake sequence in C++
- Binary Tree Longest Consecutive Sequence in C++
- Valid Permutations for DI Sequence in C++
- Find missing number in a sequence in C#
- Maximum sum Bi-tonic Sub-sequence in C++
- Binary Tree Longest Consecutive Sequence II in C++
- Find element position in given monotonic Sequence in C++
- Verify Preorder Sequence in Binary Search Tree in C++

Advertisements