Superperfect Number in C programming

A superperfect number is a positive integer that satisfies a specific mathematical condition involving the sum of divisors function. This concept was introduced by D. Suryanarayana in 1969 as a generalization of perfect numbers.

Syntax

sig(sig(n)) = 2n

Where sig(n) is the divisor summatory function that calculates the sum of all positive divisors of n (including 1 and n itself).

Example 1: Checking if 16 is Superperfect

Let's verify that 16 is a superperfect number by calculating sig(sig(16)) and comparing it with 2×16 −

sig(16) = 1 + 2 + 4 + 8 + 16 = 31
sig(31) = 1 + 31 = 32 (since 31 is prime)
2 × 16 = 32

Since sig(sig(16)) = 32 = 2×16, therefore 16 is superperfect.

Example 2: Complete C Program

Here's a complete program to check if a given number is superperfect −

#include <stdio.h>

/* Function to find the sum of all divisors of n */
int divisorSum(int n) {
    int sum = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (i == (n / i))
                sum += i;  /* Add i only once if it's a perfect square */
            else
                sum += (i + n / i);  /* Add both i and n/i */
        }
    }
    return sum;
}

int main() {
    int n = 16;
    
    printf("Checking if %d is a superperfect number:<br>", n);
    
    int sig_n = divisorSum(n);
    printf("sig(%d) = %d<br>", n, sig_n);
    
    int sig_sig_n = divisorSum(sig_n);
    printf("sig(%d) = %d<br>", sig_n, sig_sig_n);
    
    printf("2 × %d = %d<br>", n, 2 * n);
    
    if (2 * n == sig_sig_n) {
        printf("The number %d is a superperfect number<br>", n);
    } else {
        printf("The number %d is not a superperfect number<br>", n);
    }
    
    return 0;
}
Checking if 16 is a superperfect number:
sig(16) = 31
sig(31) = 32
2 × 16 = 32
The number 16 is a superperfect number

Example 3: Testing with Non-Superperfect Number

Let's test with 6 to see a non-superperfect number −

#include <stdio.h>

int divisorSum(int n) {
    int sum = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (i == (n / i))
                sum += i;
            else
                sum += (i + n / i);
        }
    }
    return sum;
}

int main() {
    int n = 6;
    
    printf("Checking if %d is a superperfect number:<br>", n);
    
    int sig_n = divisorSum(n);
    printf("sig(%d) = %d<br>", n, sig_n);
    
    int sig_sig_n = divisorSum(sig_n);
    printf("sig(%d) = %d<br>", sig_n, sig_sig_n);
    
    printf("2 × %d = %d<br>", n, 2 * n);
    
    if (2 * n == sig_sig_n) {
        printf("The number %d is a superperfect number<br>", n);
    } else {
        printf("The number %d is not a superperfect number<br>", n);
    }
    
    return 0;
}
Checking if 6 is a superperfect number:
sig(6) = 12
sig(12) = 28
2 × 6 = 12
The number 6 is not a superperfect number

Key Points

  • The divisor sum function sig(n) includes both 1 and n as divisors.
  • Known superperfect numbers include 2 and 16.
  • The algorithm has time complexity O(?n) for calculating divisor sums.

Conclusion

Superperfect numbers are rare mathematical objects where sig(sig(n)) = 2n. The efficient divisor sum calculation using the square root approach makes checking superperfect numbers computationally feasible for reasonable input ranges.

Updated on: 2026-03-15T11:28:52+05:30

610 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements