Data Structures & AlgorithmsModerateGATE CS · ICPC regional

What is the sum of (x^2 mod 13) for x = 1 to 12, taken modulo 13?

  1. A. 0
  2. B. 1
  3. C. 2
  4. D. 4

Correct answer: A. 0

The nonzero squares mod 13 are 1, 4, 9, 3, 12, 10, and each appears twice among x = 1..12, so the sum of all residues is 2 * 39 = 78, which is 0 modulo 13.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic