Skip to content

Commit acd19dc

Browse files
Merge pull request #615 from love-ode/master
Magic number code
2 parents 4c7465f + 1b4bed1 commit acd19dc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Python/magic number/magic number.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def nthMagicNo(n):
2+
3+
pow = 1
4+
answer = 0
5+
6+
# Go through every bit of n
7+
while (n):
8+
9+
pow = pow*5
10+
11+
# If last bit of n is set
12+
if (n & 1):
13+
answer += pow
14+
15+
# proceed to next bit
16+
n >>= 1 # or n = n/2
17+
18+
return answer
19+
20+
21+
# Driver program to test above function
22+
n = 10
23+
print("nth magic number is", nthMagicNo(n))
24+

0 commit comments

Comments
 (0)