ลำดับ Aliquot เป็นลำดับเลขพิเศษ ลำดับเริ่มต้นจากตัวมันเองและหมายเลขถัดไปของลำดับคือผลรวมของตัวหารที่เหมาะสมของเงื่อนไขก่อนหน้า
มาดูตัวอย่างลำดับเพื่อเรียนรู้แนวคิดกันดีกว่า −
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
จำนวนสมบูรณ์คือจำนวนที่มีลำดับส่วนหารของความยาวหนึ่ง เช่น 6 เป็นจำนวนสมบูรณ์
จำนวนที่เป็นมิตรคือตัวเลขที่มีลำดับส่วนหารของความยาวสอง ตัวอย่างเช่น 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