ProgrammingVery hardGATE CS · Campus placements

uint64_t computes 3 to the power 40 modulo 1000000007 with square-and-multiply, reducing after each multiplication. What is the result?

  1. A. 3486784401
  2. B. 953271190
  3. C. 1000000006
  4. D. 0

Correct answer: B. 953271190

Reducing after every multiply keeps each product below 2^64, so no overflow occurs. 3^40 mod 1000000007 equals 953271190. The value 3486784401 is 3^20 itself, a sign of using the wrong exponent.

More C Programming questions

Exams that ask this topic