C 程式設計中的超完全數
超完全數的概念類似於完全數。它是 D Suryanarayana 在 1969 年發現的。他將超完全數概括為滿足以下公式的數
sig(sig(n)) = 2n
此處,sig(n) 是計算數的除數和的函式,也稱為除數和函式。
以下示例將使你清楚這個概念
我們需要檢查數字 N 是否是超完全數
N = 16
輸出
yes
解釋 − 要檢查一個數字是否為完全數,我們將找到其除數的和。
sig(16) = 1 + 2 + 4 + 8 + 16 = 31 ( divisors of 16 are 1, 2, 4, 8, 16 1, 2, 4, 8, 16) sig( 31) = 1 + 31 = 32( 31 is a prime number) 2*n = 32 = sig(sig(n))
這表明 16 是一個超完全數。
現在讓我們看一個不是超完全數的數字的示例。
n = 6 sig(6) = 1 + 2 + 3 + 6= 12 sig(12) = 1 + 2 + 3 + 4 +6 + 12 = 28 6*2 = 12 != 28.
這表明 6 不是一個超完全數
示例
#include<stdio.h>
//function to find the sum of divisors of num
int divisorsum(int n){
int sum = 0; // intialising the sum
for (int i=1; i*i <= n; ++i){
if (n%i == 0) { // find the sum of divisors
if (i == (n/i))
sum += i;
else
sum += (i + n/i);
}
}
return sum;
}
int main() {
int n = 16;
int n1 = divisorsum(n);
if(2*n == divisorsum(n1)){
printf("The number %d is a superperfect number", n);
} else{
printf("The number %d is not a superperfect number", n);
}
return 0;
}輸出
The number 16 is a super perfect number
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP