Deficient Number | C # program to implement an Optimized Solution to check Deficient Number ; Function to calculate sum of divisors ; Initialize sum of prime factors ; 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 Deficient Number ; Check if sum ( n ) < 2 * n ; Driver program to test above function
using System ; class GFG { static int divisorsSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= ( Math . Sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) { sum = sum + i ; } { sum = sum + i ; sum = sum + ( n / i ) ; } } } return sum ; } static bool isDeficient ( int n ) { return ( divisorsSum ( n ) < ( 2 * n ) ) ; } public static void Main ( ) { string var = isDeficient ( 12 ) ? " YES " : " NO " ; Console . WriteLine ( var ) ; string var1 = isDeficient ( 15 ) ? " YES " : " NO " ; Console . WriteLine ( var1 ) ; } }