Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Starting at the number 2, repeatedly apply f(x) = x² + 1 modulo 11. What is the value after 5 applications?

  1. A. 4
  2. B. 5
  3. C. 1
  4. D. 6

Correct answer: D. 6

2 → 5 → 26 ≡ 4 → 17 ≡ 6 → 37 ≡ 4 → 17 ≡ 6, so after five steps the value is 6 (it alternates 4, 6). Stopping after four gives 4, one step gives 5, and reducing mod 10 gives 1.

More Coding Interview Problems questions

Exams that ask this topic