text: Superabundant Numbers | C ++ implementation to check if a number is Superabundant ; Function to calculate the sum of all divisors of a given number ; Sum of divisors ; find all divisors which divides ' num ' ; if ' i ' is divisor of ' n ' ; if both divisors are same then add it once else add both ; Add 1 and n to result as above loop considers proper divisors greater than 1. ; Function to check if N is a superabundant number ; to check all numbers from 1 to N ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int sigma ( int n ) { if ( n == 1 ) return 1 ; int result = 0 ; for ( int i = 2 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( i == ( n / i ) ) result += i ; else result += ( i + n / i ) ; } } return ( result + n + 1 ) ; } bool isSuperabundant ( int N ) { for ( float i = 1 ; i < N ; i ++ ) { float x = sigma ( i ) / i ; float y = sigma ( N ) / ( N * 1.0 ) ; if ( x > y ) return false ; } return true ; } int main ( ) { int N = 4 ; isSuperabundant ( N ) ? cout << " Yes " : cout << " No " ; return 0 ; }