Print prime factors of a given integer in decreasing order using Stack | Function to print prime factors of N in decreasing order ; Stores prime factors of N in decreasing order ; Insert i into stack ; Update N ; Update i ; Print value of stack st ; Driver Code ; function Call
def PrimeFactors ( N ) : NEW_LINE INDENT st = [ ] NEW_LINE i = 2 NEW_LINE while ( N != 1 ) : NEW_LINE INDENT if ( N % i == 0 ) : NEW_LINE INDENT st . append ( i ) NEW_LINE while ( N % i == 0 ) : NEW_LINE INDENT N = N // i NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT while ( len ( st ) != 0 ) : NEW_LINE INDENT print ( st [ - 1 ] ) NEW_LINE st . pop ( ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 8 NEW_LINE PrimeFactors ( N ) NEW_LINE DEDENT