🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Number Theory for Coding: all 10 questions

Quiz: Number Theory for Coding · Question 8 of 10

What does this print? (code)

What does this print?

def power(b, e, m):
    r = 1
    while e:
        if e & 1:
            r = r * b % m
        b = b * b % m
        e >>= 1
    return r
print(power(2, 10, 1000), power(5, 3, 7))
  1. A.1024 6
  2. B.24 6
  3. C.24 125
  4. D.1024 125
Answer & explanation

Correct answer: 24 6

2¹⁰ = 1024, and 1024 mod 1000 = 24. 5³ = 125 = 17 × 7 + 6.

Can you get the rest right without peeking?

Take the timed Quiz: Number Theory for Coding quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →