Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1.) ARGUMENT OF CORRECTNESS FOR CODE 2.) RUNTIME ANALYSIS FOR CODE CODE: '''returns the largest integer x such that x^k does not exceed n, assuming
1.) ARGUMENT OF CORRECTNESS FOR CODE
2.) RUNTIME ANALYSIS FOR CODE
CODE:
'''returns the largest integer x such that x^k does not exceed n,
assuming k and n are both positive integers'''
def iroot(k, n):
num=1
#looping until num^k is greater than n
while True:
#checking if current number ^ k is greater than n
if pow(num,k)>n:
#returning previous number
return num-1
#moving to next number
num+=1
#testing various cases
print(iroot(3,125)) #5
print(iroot(3,126)) #5
print(iroot(3,124)) #4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started