Find nth Magic Number | Function to find nth magic number ; Go through every bit of n ; If last bit of n is set ; proceed to next bit $n >>= 1 ; or $n = $n / 2 ; Driver Code
< ? php function nthMagicNo ( $ n ) { $ pow = 1 ; $ answer = 0 ; while ( $ n ) { $ pow = $ pow * 5 ; if ( $ n & 1 ) $ answer += $ pow ; } return $ answer ; } $ n = 5 ; echo " nth ▁ magic ▁ number ▁ is ▁ " , nthMagicNo ( $ n ) , " STRNEWLINE " ; ? >