Panarithmic numbers within a given range | function to compute divisors of a number ; vector to store divisors ; 1 will always be a divisor ; check if i is squareroot of A then only one time insert it in ans ; function to check that a number can be represented as sum of distinct divisor or not ; The value of subset [ i ] [ j ] will be true if there is a subset of set [ 0. . j - 1 ] with sum equal to i ; If sum is 0 , then answer is true ; If sum is not 0 and set is empty , then answer is false ; Fill the subset table in bottom up manner ; return the possibility of given sum ; function to check a number is Practical or not ; vector to store divisors ; if all numbers can be represented as sum of unique divisors ; function to print Practical Numbers in a range ; Driver Function
function get_divisors ( A ) { var ans = [ ] ; ans . push ( 1 ) ; for ( var i = 2 ; i <= Math . sqrt ( A ) ; i ++ ) { if ( A % i == 0 ) { ans . push ( i ) ; if ( ( i * i ) != A ) ans . push ( parseInt ( A / i ) ) ; } } return ans ; } function Sum_Possible ( set , sum ) { var n = set . length ; var subset = Array . from ( Array ( n + 1 ) , ( ) => Array ( sum + 1 ) ) ; for ( var i = 0 ; i <= n ; i ++ ) subset [ i ] [ 0 ] = true ; for ( var i = 1 ; i <= sum ; i ++ ) subset [ 0 ] [ i ] = false ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = 1 ; j <= sum ; j ++ ) { if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ; if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ; } } return subset [ n ] [ sum ] ; } function Is_Practical ( A ) { var divisors = [ ] ; divisors = get_divisors ( A ) ; for ( var i = 2 ; i < A ; i ++ ) { if ( Sum_Possible ( divisors , i ) == false ) return false ; } return true ; } function print_practica_No ( A , B ) { for ( var i = A ; i <= B ; i ++ ) { if ( Is_Practical ( i ) == true ) { document . write ( i + " " ) ; } } } var A = 1 , B = 100 ; print_practica_No ( A , B ) ;