Find the super power of a given Number | PHP 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 Code
< ? php $ MAX = 100000 ; $ prime = array_fill ( 0 , 100002 , true ) ; function SieveOfEratosthenes ( ) { global $ MAX , $ prime ; for ( $ p = 2 ; $ p * $ p <= $ MAX ; $ p ++ ) if ( $ prime [ $ p ] == true ) for ( $ i = $ p * 2 ; $ i <= $ MAX ; $ i += $ p ) $ prime [ $ i ] = false ; } function superpower ( $ n ) { SieveOfEratosthenes ( ) ; global $ MAX , $ prime ; $ superPower = 0 ; $ factor = 0 ; $ 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 ; } $ n = 256 ; echo superpower ( $ n ) ; ? >