Check if a number can be expressed as sum two abundant numbers | Function to return all abundant numbers This function will be helpful for multiple queries ; To store abundant numbers ; to store sum of the divisors include 1 in the sum ; if j is proper divisor ; if i is not a perfect square ; if sum is greater than i then i is a abundant number ; Check if number n is expressed as sum of two abundant numbers ; if both i and n - i are abundant numbers ; can not be expressed ; Driver code
< ? php function ABUNDANT ( ) { $ N = 100005 ; $ v = array ( ) ; for ( $ i = 1 ; $ i < $ N ; $ i ++ ) { $ sum = 1 ; for ( $ j = 2 ; $ j * $ j <= $ i ; $ j ++ ) { if ( $ i % $ j == 0 ) { $ sum += $ j ; if ( $ i / $ j != $ j ) $ sum += $ i / $ j ; } } if ( $ sum > $ i ) array_push ( $ v , $ i ) ; } $ v = array_unique ( $ v ) ; return $ v ; } function SumOfAbundant ( $ n ) { $ v = ABUNDANT ( ) ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { if ( in_array ( $ i , $ v ) && in_array ( $ n - $ i , $ v ) ) { echo $ i , " ▁ " , $ n - $ i ; return ; } } echo - 1 ; } $ n = 24 ; SumOfAbundant ( $ n ) ; ? >