Skip to content

Commit

Permalink
Finding the nth root in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
Garvit244 committed Oct 3, 2017
1 parent 3fe2610 commit 3992cba
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions algebra/nth_root/python/nth_root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Find the nth root of a and return the integer component only
@input: number, root
@output: nth root of number
"""
def nth_root(a,n):
high = 1
while high ** n <= a:
high *= 2
low = high/2
while low < high:
mid = (low + high) // 2
if low < mid and mid**n < a:
low = mid
elif high > mid and mid**n > a:
high = mid
else:
return mid
return mid + 1

0 comments on commit 3992cba

Please sign in to comment.