ProgrammingVery hardCodeforces-style · placement coding round

What is printed?

What is printed?
def egcd(a, b):
    if b == 0:
        return a, 1, 0
    g, x, y = egcd(b, a % b)
    return g, y, x - (a // b) * y
g, x, y = egcd(240, 46)
print(g, 240 * x + 46 * y)
  1. A. 2 0
  2. B. 2 2
  3. C. 46 2
  4. D. 1 2

Correct answer: B. 2 2

The recursive extended Euclidean algorithm returns g together with x and y such that 240x + 46y = g. Here g is 2, and the combination also equals 2.

More Python Programming questions

Exams that ask this topic