ProgrammingVery hardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned long long r = 1, b = 7;
int e = 222;
while (e) {
if (e & 1) r = r * b % 1000;
b = b * b % 1000;
e >>= 1;
}
printf("%llu", r);
}- A. 343
- B. 7
- C. 1
- D. 49
Correct answer: D. 49
Binary exponentiation computes 7^222 mod 1000, and the result is 49. Every product is reduced before it is stored, so no intermediate value overflows.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { unsigned h = 0; for (const char s = "abcdefgh"; s; s++) h = (h << 5) ^ (unsigned…
- What is printed? c #include <stdio.h> int pc(int x) { int c = 0; while (x) { c += x & 1; x >>= 1; } return c; } int cmp(const void a…
- What is printed? c #include <stdio.h> int C(int n) { if (n == 0) return 1; int s = 0; for (int i = 0; i < n; i++) s += C(i) C(n - 1 - i)…
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = (unsigned)-5; printf("%u", x >> 31); }
- What is printed? c #include <stdio.h> int main(void) { int m[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (p)[3] = m; p++; printf("%d", p); }
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0xA8; printf("%u", x & (0u - x)); }