Superperfect Number In C

In the realm of mathematical theory, a "super-perfect number" is an extension of the concept of perfect numbers. A superperfect number is defined as a positive integer, denoted as n, where 2n encompasses all divisors of n, including n itself.

A superperfect number is a number that meets the criteria outlined by the following formula:

Example

sig(sig(n)) = 2n

Here, sig(n) is referred to as the divisor summatory function, which calculates the total sum of a number's divisors.

Example:

Let's verify if the value N qualifies as a superperfect number or not:

Example

Input:

N = 16

Output:

yes

Explanation:

The function sig(16) calculates the sum of all divisors of 16, which are 1, 2, 4, 8, and 16, resulting in a total of 31.

sig(31)=1+31=32(31 is prime number)

The equation 2 times n equals 32, which is equivalent to the sum of the sum of n. This demonstrates that 16 is a super perfect number.

Now, let's examine another instance of a number that does not qualify as a superperfect integer.

Example

Input:

N = 6

Output:

no

sig(6) = 1 + 2 + 3 + 6= 12

sig(12) = 1 + 2 + 3 + 4 +6 + 12 = 28

Multiplying 6 by 2 results in 12, which is not equal to 28. This demonstrates that 6 is not a super perfect number.

Code Implementation:

Let's consider a C program to verify if a given number is a superperfect number or not:-

Example

#include<stdio.h>

int divisorsum(int n){

   int sum = 0; 

   for (int a=1; a*a <= n; ++a){

      if (n%a == 0) { 

         if (a == (n/a))

            sum += a;

         else

            sum += (a + n/a);

      }

   }

   return sum;

}

int main() {

   int n = 64;

   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:

Output

[Program Output]

Explanation:

The sum of divisors of 64, denoted as σ(64), is calculated as 1 + 2 + 4 + 8 + 16 + 32 + 64, resulting in a value of 127. The divisors of 64 include 1, 2, 4, 8, 16, 32, and 64.

sig(127)=1+127=128(127 is a prime number)

Example

2*n = 128 = sig(sig(n))
  • This demonstrates that 64 qualifies as a superperfect number.
  • Complexity Analysis:

Time Complexity:

It has the time complexity of O(sqrt(n)).

Space Complexity:

It has the space complexity of O(1).

Input Required

This code uses input(). Please provide values below: