1)What would happen if we call gcd(m,n) with m positive and n negative in the following definition?
def gcd(m,n): if m < n: (m,n) = (n,m) if (m % n) == 0: return(n) else: diff = m-n return (gcd(max(n,diff),min(n,diff)))
Answer : (a)
2)What can we say about a number n if h(n) returns True for the function h given below?
def h(n): for i in range(2,n): if n%i == 0: return(True) return(False)
Answer : (b) n is a composite number.
3)What does f(120,13) return for the following function defintion?
def f(m,n): ans = 1 while (m - n >= 0): (ans,m) = (ans*2,m-n) return(ans)
Answer : 512.
4)What does g(9000,3) return for the following function definition?
def g(x,y): val = 0 while (x > y): (val,x) = (val+1,x/y) return(val)
Answer : 8