ProgrammingVery hardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdint.h>
#include <stdio.h>
uint64_t pw(uint64_t b, uint64_t e, uint64_t m) {
    uint64_t r = 1;
    b %= m;
    while (e) {
        if (e & 1) r = r * b % m;
        b = b * b % m;
        e >>= 1;
    }
    return r;
}
int main(void) {
    printf("%llu", (unsigned long long)pw(2, 100, 1000000007ULL));
}
  1. A. 988185646
  2. B. 1024
  3. C. 0
  4. D. 976371285

Correct answer: D. 976371285

With 64-bit operands every product stays below 2^64, so the result is exactly 2^100 mod 1000000007. Using the exponent 99 gives 988185646, and skipping exponent bits by shifting two at a time gives 1024.

More C Programming questions

Exams that ask this topic