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 ] | 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
function primeFactor ( N ) { let v = [ ] ; let count = 0 ; while ( ! ( N % 2 ) ) { N >>= 1 ; count ++ ; } if ( count ) v . push ( [ 2 , count ] ) ; for ( let i = 3 ; i <= Math . sqrt ( N ) ; i += 2 ) { count = 0 ; while ( N % i == 0 ) { count ++ ; N = Math . floor ( N / i ) ; } if ( count ) { v . push ( [ i , count ] ) ; } } if ( N > 2 ) v . push ( [ N , 1 ] ) ; return v ; } function printAnswer ( n ) { let v = primeFactor ( n ) ; let maxi_size = 0 , prime_factor = 0 ; for ( let i = 0 ; i < v . length ; i ++ ) { if ( maxi_size < v [ i ] [ 1 ] ) { maxi_size = v [ i ] [ 1 ] ; prime_factor = v [ i ] [ 0 ] ; } } if ( maxi_size < 2 ) { document . write ( 1 + ' ' + n ) ; } else { let product = 1 ; document . write ( maxi_size + " " ) ; for ( let i = 0 ; i < maxi_size - 1 ; i ++ ) { document . write ( prime_factor + " " ) ; product *= prime_factor ; } document . write ( Math . floor ( ( n / product ) ) ) ; } } let N = 360 ; printAnswer ( N ) ;