Check if a number can be expressed as sum two abundant numbers | javascript program to check if number n is expressed as sum of 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
var N = 100005 ; function ABUNDANT ( ) { var v = new Set ( ) ; var i , j ; for ( i = 1 ; i < N ; i ++ ) { var sum = 1 ; for ( j = 2 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { sum += j ; if ( parseInt ( i / j ) != j ) sum += parseInt ( i / j ) ; } } if ( sum > i ) v . add ( i ) ; } return v ; } function SumOfAbundant ( n ) { var v = new Set ( ) ; v = ABUNDANT ( ) ; var i ; for ( i = 1 ; i <= n ; i ++ ) { if ( v . has ( i ) && v . has ( n - i ) ) { document . write ( i + ' ' + ( n - i ) ) return ; } } document . write ( - 1 ) ; } var n = 24 ; SumOfAbundant ( n ) ;