Number less than equals to N with maximum product of prime factors | Function to find the smallest number having a maximum product of prime factors ; Declare the list arr ; Initialise list with 1 ; Iterate from [ 2 , N ] ; If value at index i is 1 , then i is prime and make update list at index for all multiples of i ; Initialise maxValue ; Find number having maximum product of prime factor <= N ; Find the maximum value ; Given number ; Function call
def maxPrimefactorNum ( N ) : NEW_LINE INDENT arr = [ ] NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT arr . append ( 1 ) NEW_LINE DEDENT for i in range ( 2 , N + 1 ) : NEW_LINE INDENT if ( arr [ i ] == 1 ) : NEW_LINE INDENT for j in range ( i , N + 1 , i ) : NEW_LINE INDENT arr [ j ] *= i NEW_LINE DEDENT DEDENT DEDENT maxValue = 1 NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT if ( arr [ i ] > maxValue ) : NEW_LINE INDENT maxValue = i NEW_LINE DEDENT DEDENT return maxValue NEW_LINE DEDENT N = 20 ; NEW_LINE print ( maxPrimefactorNum ( N ) ) NEW_LINE