ProgrammingVery hardCompetitive coding (CP)

What is printed? Assume uint64t is 64 bits.

What is printed? Assume uint64_t is 64 bits.
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint64_t r = 1;
    for (uint64_t i = 1; i <= 20; i++)
        r = r * i % 1000000007ULL;
    printf("%llu", (unsigned long long)r);
}
  1. A. 146326063
  2. B. 146326064
  3. C. 146326062
  4. D. 2432902008176640000

Correct answer: A. 146326063

Reducing modulo 1000000007 after every multiplication keeps each product below 10^18, so the result is 20! mod 1000000007 = 146326063. The fourth option is 20! itself, which is never printed by this program.

More C Programming questions

Exams that ask this topic