Find the super power of a given Number | Javascript for finding super power of n ; global hash for prime ; sieve method for storing a list of prime ; function to return super power ; find the super power ; Driver program
var MAX = 100000 ; var prime = Array ( 100002 ) . fill ( true ) ; function SieveOfEratosthenes ( ) { for ( var p = 2 ; p * p <= MAX ; p ++ ) if ( prime [ p ] == true ) for ( var i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } function superpower ( n ) { SieveOfEratosthenes ( ) ; var superPower = 0 , factor = 0 ; var i = 2 ; while ( n > 1 && i <= MAX ) { if ( prime [ i ] ) { factor = 0 ; while ( n % i == 0 && n > 1 ) { factor ++ ; n = n / i ; } if ( superPower < factor ) superPower = factor ; } i ++ ; } return superPower ; } var n = 256 ; document . write ( superpower ( n ) ) ;