text: Weird Number | code to find all the factors of the number excluding the number itself ; vector to store the factors ; note that this loop runs till sqrt ( n ) ; if the value of i is a factor ; condition to check the divisor is not the number itself ; return the vector ; Function to check if the number is abundant or not ; find the divisors using function ; sum all the factors ; check for abundant or not ; Function to check if the number is semi - perfect or not ; find the divisors ; sorting the vector ; subset to check if no is semiperfect ; initialising 1 st column to true ; initialing 1 st row except zero position to 0 ; loop to find whether the number is semiperfect ; calculation to check if the number can be made by summation of divisors ; if not possible to make the number by any combination of divisors ; Function to check for weird or not ; Driver Code
code: function factors ( n ) { var v = [ ] ; v . push ( 1 ) ; for ( var i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v . push ( i ) ; if ( n / i != i ) { v . push ( n / i ) ; } } } return v ; } function checkAbundant ( n ) { var v = [ ] ; var sum = 0 ; v = factors ( n ) ; for ( var i = 0 ; i < v . length ; i ++ ) { sum += v [ i ] ; } if ( sum > n ) return true ; else return false ; } function checkSemiPerfect ( n ) { var v = [ ] ; v = factors ( n ) ; v . sort ( ) var r = v . length ; var subset = Array . from ( Array ( r + 1 ) , ( ) => Array ( n + 1 ) ) ; for ( var i = 0 ; i <= r ; i ++ ) subset [ i ] [ 0 ] = true ; for ( var i = 1 ; i <= n ; i ++ ) subset [ 0 ] [ i ] = false ; for ( var i = 1 ; i <= r ; i ++ ) { for ( var j = 1 ; j <= n ; j ++ ) { if ( j < v [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ; else { subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - v [ i - 1 ] ] ; } } } if ( ( subset [ r ] [ n ] ) == 0 ) return false ; else return true ; } function checkweird ( n ) { if ( checkAbundant ( n ) == true && checkSemiPerfect ( n ) == false ) return true ; else return false ; } var n = 70 ; if ( checkweird ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;