🎙 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 10 of 10

Under modulo M = 10⁹ + 7, how do you correctly compute (a / b) mod M?

Under modulo M = 10⁹ + 7, how do you correctly compute (a / b) mod M?

  1. A.(a % M) / (b % M)
  2. B.a × b^(M − 2) mod M, using fast power for the inverse of b
  3. C.(a / b) % M with integer division
  4. D.a mod (b × M)
Answer & explanation

Correct answer: a × b^(M − 2) mod M, using fast power for the inverse of b

Fermat's little theorem gives the inverse of b when M is prime and b is not a multiple of M.

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 →