← 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))
- A.1024 6
- B.24 6
- C.24 125
- 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 →