等分序列是数字的特殊序列。序列从数字本身开始,序列的下一个数字是前一项的适当除数之和。
让我们以顺序的例子来更好地学习概念-
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
完美数字是长度为1的等分序列的数字。例如,6是一个完美数。
亲和号码是长度为2的等分序列的号码。例如,1是可和数字。
社交号码是长度为三的等分序列的号码。例如,7是一个可关联数字。
从数字计算等高序列。我们需要计算该术语的适当除数。为了计算这一点,我们将使用除法算法。
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.
#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;
}输出结果
45 33 15 9 4 3 1 0