Primitive Abundant Number | C ++ implementation of the above approach ; Function to sum of divisors ; Note that this loop runs till square root of N ; If divisors are equal , take only one of them ; else Otherwise take both ; Function to check Abundant Number ; Return true if sum of divisors is greater than N . ; Function to check Deficient Number ; Check if sum ( n ) < 2 * n ; Function to check all proper divisors of N is deficient number or not ; if number itself is not abundant return false ; find all divisors which divides ' num ' ; if ' i ' is divisor of ' num ' ; if both divisors are same then add it only once else add both ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) sum = sum + i ; { sum = sum + i ; sum = sum + ( n / i ) ; } } } return sum ; } bool checkAbundant ( int n ) { return ( getSum ( n ) - n > n ) ; } bool isDeficient ( int n ) { return ( getSum ( n ) < ( 2 * n ) ) ; } bool checkPrimitiveAbundant ( int num ) { if ( ! checkAbundant ( num ) ) { return false ; } for ( int i = 2 ; i <= sqrt ( num ) ; i ++ ) { if ( num % i == 0 && i != num ) { if ( i * i == num ) { if ( ! isDeficient ( i ) ) { return false ; } } else if ( ! isDeficient ( i ) || ! isDeficient ( num / i ) ) { return false ; } } } return true ; } int main ( ) { int n = 20 ; if ( checkPrimitiveAbundant ( n ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }