Panarithmic numbers within a given range | Python3 program to print Practical Numbers in 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 summ of distinct divisor or not ; The value of subsett [ i ] [ j ] will be True if there is a subsett of sett [ 0. . j - 1 ] with summ equal to i ; If summ is 0 , then answer is True ; If summ is not 0 and sett is empty , then answer is False ; Fill the subsett table in bottom up manner ; Return the possibility of given summ ; Function to check a number is Practical or not ; Vector to store divisors ; If all numbers can be represented as summ of unique divisors ; Function to prPractical Numbers in a range ; Driver code
import math NEW_LINE def get_divisors ( A ) : NEW_LINE INDENT ans = [ ] NEW_LINE ans . append ( 1 ) NEW_LINE for i in range ( 2 , math . floor ( math . sqrt ( A ) ) + 1 ) : NEW_LINE INDENT if ( A % i == 0 ) : NEW_LINE INDENT ans . append ( i ) NEW_LINE if ( ( i * i ) != A ) : NEW_LINE INDENT ans . append ( A // i ) NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT def summ_Possible ( sett , summ ) : NEW_LINE INDENT n = len ( sett ) NEW_LINE subsett = [ [ 0 for i in range ( summ + 1 ) ] for j in range ( n + 1 ) ] NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT subsett [ i ] [ 0 ] = True NEW_LINE DEDENT for i in range ( 1 , summ + 1 ) : NEW_LINE INDENT subsett [ 0 ] [ i ] = False NEW_LINE DEDENT for i in range ( n + 1 ) : NEW_LINE INDENT for j in range ( summ + 1 ) : NEW_LINE INDENT if ( j < sett [ i - 1 ] ) : NEW_LINE INDENT subsett [ i ] [ j ] = subsett [ i - 1 ] [ j ] NEW_LINE DEDENT if ( j >= sett [ i - 1 ] ) : NEW_LINE INDENT subsett [ i ] [ j ] = ( subsett [ i - 1 ] [ j ] or subsett [ i - 1 ] [ j - sett [ i - 1 ] ] ) NEW_LINE DEDENT DEDENT DEDENT return subsett [ n ] [ summ ] NEW_LINE DEDENT def Is_Practical ( A ) : NEW_LINE INDENT divisors = [ ] NEW_LINE divisors = get_divisors ( A ) NEW_LINE for i in range ( 2 , A ) : NEW_LINE INDENT if ( summ_Possible ( divisors , i ) == False ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def print_practica_No ( A , B ) : NEW_LINE INDENT for i in range ( A , B + 1 ) : NEW_LINE INDENT if ( Is_Practical ( i ) == True ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT A = 1 NEW_LINE B = 100 NEW_LINE print_practica_No ( A , B ) NEW_LINE