Superperfect Number in C programming


The concept of super perfect number is similar to the perfect number. It was found by D Suryanarayana in 1969. He generalized the super perfect number as a number that satisfies the following formula :

sig(sig(n)) = 2n

Here, sig(n) is the function that calculates the sum of divisors of a number, it is also known as divisor summatory function.

The following example with making this concept clear to you :

we need to check if the number N is a superperfect number or not:

N = 16

Output

yes

Explanation − to check whether a number is a perfect number or not we will find the sum of its divisors.

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))

This shows that 16 is a superperfect number.

Now let's see an example of a number which is not a superperfect number.

n = 6
sig(6) = 1 + 2 + 3 + 6= 12
sig(12) = 1 + 2 + 3 + 4 +6 + 12 = 28
6*2 = 12 != 28.

This shows that 6 is not a super perfect number

Example

#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;
}

Output

The number 16 is a super perfect number

Updated on: 13-Aug-2019

266 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements