I would like help solving this practice question.
For a function f(x, y) defined below, what is the value of f(775, 527)? Here, x mod y represents the remainder after division of x by y.
f(x, y): if y = 0 then return x else return f(y, x mod y)
So it's saying x mod y represents 248?
Using the function definition, y does not equal 0 so that means I need to return f(y, x mod y).
775 mod 527 = 248
775 / 527 = 1 r248
f(527, 775 mod 527) -> f(527, 248) -> 527 mod 248 = 31
I was able to figure out the correct answer 31, however I don't see where it tells me 527, 248 should be solved as x mod y.
return x else return f(y, x mod y). How did you know thatf(y, x mod y)is the same asgcd(x,y)And how do you know thatgcd(x,y)means the same asx (mod y)? Like how did we get fromf(527, 248)to527 mod 248? – Edison Aug 07 '19 at 21:02