<?php // PHP program to find nth // magic number // Function to find nth // magic number function nthMagicNo($n) { $pow = 1; $answer = 0; // Go through every bit of n while ($n) { $pow = $pow * 5; // If last bit of n is set if ($n & 1) $answer += $pow; // proceed to next bit $n >>= 1; // or $n = $n/2 } return $answer; } // Driver Code $n = 5; echo "nth magic number is ", nthMagicNo($n), "\n"; // This code is contributed by Ajit. ?>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter