Data Structures & AlgorithmsHardICPC regional · GATE CS

Problem: How many integers x with 0 ≤ x ≤ 99 satisfy x³ ≡ x (mod 7)?

  1. A. 43
  2. B. 30
  3. C. 15
  4. D. 44

Correct answer: D. 44

x³ ≡ x means x(x − 1)(x + 1) ≡ 0, so x ≡ 0, 1 or 6 (mod 7). In 0..99 that is 15 + 15 + 14 = 44. Starting at 1 gives 43, forgetting x ≡ −1 gives 30, and only x ≡ 0 gives 15.

More Coding Interview Problems questions

Exams that ask this topic