Data Structures & AlgorithmsHardCodeforces Div2 B · number theory

Problem: What is 6! mod 7, the value predicted by Wilson's theorem for a prime p = 7 (where (p-1)! ≡ -1 mod p, i.e. 6 mod 7)? Run the code.

Problem: What is 6! mod 7, the value predicted by Wilson's theorem for a prime p = 7 (where (p-1)! ≡ -1 mod p, i.e. 6 mod 7)? Run the code.
from math import factorial
print(factorial(6) % 7)
What is printed?
  1. A. 6
  2. B. 1
  3. C. 0
  4. D. 5

Correct answer: A. 6

720 mod 7 = 6, which equals -1 mod 7, as Wilson's theorem states for prime moduli.

More Coding Interview Problems questions

Exams that ask this topic