

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Aliquot sum in C++?
- Permutation Sequence in C++
- Modify sequence in MongoDB
- Collatz sequence in Python
- Connell sequence in Python
- Sequence Reconstruction in C++
- Python Sequence Types
- Sort strings in Alphanumeric sequence
- The Fibonacci sequence in Javascript
- Longest Arithmetic Sequence in C++
- Longest Consecutive Sequence in Python
- Stamping The Sequence in C++
- Fibonacci like sequence in JavaScript
- Shortest Common Super Sequence
- Python Text Sequence Types
Advertisements