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?
- A. 6
- B. 1
- C. 0
- 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
- Problem: How many integers in [1, 50] are divisible by both 2 and 3? Run the code. python print(sum(1 for x in range(1, 51) if x % 2 == 0…
- Problem: What is the sum of the first 10 odd positive integers? Run the code. python print(sum(2 i + 1 for i in range(10))) What is printed?
- Problem: How many 2-digit numbers have both digits odd? Run the code. python print(sum(1 for x in range(10, 100) if int(str(x)[0]) % 2 ==…
- Problem: How many pairs (i < j) of [1, 3, 5, 7, 9] have a[i] + a[j] >= 10? Run the code. python a = [1, 3, 5, 7, 9] print(sum(1 for i in…
- Problem: What is the maximum sum of any 3 consecutive elements of [1, -2, 3, 4, -1]? Run the code. python a = [1, -2, 3, 4, -1]…
- Problem: How many integers in [1, 100] are perfect squares or perfect cubes? Run the code. python sq = {x x for x in range(1, 11)} cu = {x…