You want to be able to multiply two 64-bit numbers, so you need a 128 bit result. The easiest fix is to use gcc's 128 bit type (presumably MS has something similar). Alternatively, you can use a bignum library (or make your own 128-bit multiply and modulus).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
uint64_t expmod(uint64_t base, uint64_t exponent, uint64_t modulus) {
uint64_t result = 1;
while (exponent > 0) {
if (exponent & 1)
result = ((__uint128_t)result * base) % modulus;
base = ((__uint128_t)base * base) % modulus;
exponent >>= 1;
}
return result;
}
int main() {
uint64_t base = 888999000,
exponent = 202404606,
modulus = 237291793913;
std::cout << expmod(base, exponent, modulus) << '\n'; // 202609913015
}