Generate a sequence with product N such that for every pair of indices ( i , j ) and i < j , arr [ j ] is divisible by arr [ i ] | Python3 program for the above approach ; Function to calculate the prime factors of N with their count ; Initialize a vector , say v ; Initialize the count ; Count the number of divisors ; Divide the value of N by 2 ; For factor 2 divides it ; Find all prime factors ; Count their frequency ; Push it to the vector ; Push N if it is not 1 ; Function to print the array that have the maximum size ; Stores the all prime factor and their powers ; Traverse the vector and find the maximum power of prime factor ; If max size is less than 2 ; Otherwise ; Print the maximum size of sequence ; Print the final sequence ; Print the prime factor ; Print the last value of the sequence ; Driver Code
from math import sqrt NEW_LINE def primeFactor ( N ) : NEW_LINE INDENT v = [ ] NEW_LINE count = 0 NEW_LINE while ( ( N % 2 ) == 0 ) : NEW_LINE INDENT N >>= 1 NEW_LINE count += 1 NEW_LINE DEDENT if ( count ) : NEW_LINE INDENT v . append ( [ 2 , count ] ) NEW_LINE DEDENT for i in range ( 3 , int ( sqrt ( N ) ) + 1 , 2 ) : NEW_LINE INDENT count = 0 NEW_LINE while ( N % i == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE N = N / i NEW_LINE DEDENT if ( count ) : NEW_LINE INDENT v . append ( [ i , count ] ) NEW_LINE DEDENT DEDENT if ( N > 2 ) : NEW_LINE INDENT v . append ( [ N , 1 ] ) NEW_LINE DEDENT return v NEW_LINE DEDENT def printAnswer ( n ) : NEW_LINE INDENT v = primeFactor ( n ) NEW_LINE maxi_size = 0 NEW_LINE prime_factor = 0 NEW_LINE for i in range ( len ( v ) ) : NEW_LINE INDENT if ( maxi_size < v [ i ] [ 1 ] ) : NEW_LINE INDENT maxi_size = v [ i ] [ 1 ] NEW_LINE prime_factor = v [ i ] [ 0 ] NEW_LINE DEDENT DEDENT if ( maxi_size < 2 ) : NEW_LINE INDENT print ( 1 , n ) NEW_LINE DEDENT else : NEW_LINE INDENT product = 1 NEW_LINE print ( maxi_size ) NEW_LINE for i in range ( maxi_size - 1 ) : NEW_LINE INDENT print ( prime_factor , end = " ▁ " ) NEW_LINE product *= prime_factor NEW_LINE DEDENT print ( n // product ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 360 NEW_LINE printAnswer ( N ) NEW_LINE DEDENT