Elements of Array which can be expressed as power of prime numbers | Function to mark all the exponent of prime numbers ; If number is prime then marking all of its exponent true ; Function to display all required elements ; Function to print the required numbers ; To find the largest number ; Function call to mark all the Exponential prime nos . ; Function call ; Driver code
function ModifiedSieveOfEratosthenes ( N , Expo_Prime ) { let primes = new Array ( N ) ; primes . fill ( true ) for ( let i = 2 ; i < N ; i ++ ) { if ( primes [ i ] ) { let no = i ; while ( no <= N ) { Expo_Prime [ no ] = true ; no *= i ; } for ( let j = i * i ; j < N ; j += i ) primes [ j ] = false ; } } } function Display ( arr , Expo_Prime , n ) { for ( let i = 0 ; i < n ; i ++ ) if ( Expo_Prime [ arr [ i ] ] ) document . write ( arr [ i ] + " " ) ; } function FindExpoPrime ( arr , n ) { let max = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( max < arr [ i ] ) max = arr [ i ] ; } let Expo_Prime = new Array ( max + 1 ) ; Expo_Prime . fill ( false ) ModifiedSieveOfEratosthenes ( max + 1 , Expo_Prime ) ; Display ( arr , Expo_Prime , n ) ; } let arr = [ 4 , 6 , 9 , 16 , 1 , 3 , 12 , 36 , 625 , 1000 ] ; let n = arr . length FindExpoPrime ( arr , n ) ;