Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Write a function ' powr(x,n) ' that will compute x^n (x to the power of n where n >= 0). Obviously, you should not use the built-in Python operator (or library functions) to accomplish this. Do the...

1 answer below »
  • Write a function 'powr(x,n)' that will computex^n(x to the power of n where n >= 0). Obviously, you should not use the built-in Python operator (or library functions) to accomplish this. Do the computation manually (Hint: loop). Pay attention to the algorithmic complexity. What is the best possible big-O? Example: powr(3,2) -> 9
  • Write a function 'prime(x,y)' that calculates the prime numbers for a given range specified by the two parameters. For example, if x is 100 and y is 200, your function should print the following: 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199. What is the best possible big-O?
Answered Same Day Sep 18, 2021

Solution

Arun Shankar answered on Sep 18 2021
154 Votes
def powr(x,n):
if(n == 0):
return 1
if(n % 2 == 0):
return powr(x, n / 2) * powr(x, n / 2)
return x * powr(x, n
2) * powr(x, n
2)
def isPrime(n):
if(n == 1):
return False
if(n == 2):
return True
for i in range(2, n - 1):
if(n % i == 0):
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here