Data Structures & AlgorithmsModerateTCS NQT Digital · CAT

Problem: The sum of the squares of the first 15 natural numbers, reduced modulo 7, is what value?

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

Correct answer: C. 1

Use the closed form n(n+1)(2n+1)/6 = 1240 for n = 15, then reduce modulo 7 to get 1. Summing squares directly gives the same result.

More Coding Interview Problems questions

Exams that ask this topic