Question 61
What is the return value of power_mod(2, 10, 1000)?
CODE
int power_mod(int b, int e, int m) {
if (e == 0) return 1;
long long t = power_mod(b, e / 2, m);
t = (t * t) % m;
if (e % 2 != 0) t = (t * b) % m;
return t;
}Detailed Solution
$2^10$ = 1024; 1024 % 1000 = 24.
✓ Saved