3^7338 mod 310448767 yields "Error: Unknown Function 'mod'" on the calculator,
though other smaller numbers work fine. I just tried it with this and got 244095518,
was looking for something to verify it with... Cheers.
unsigned long long long_pow_mod(unsigned long long base,
unsigned long long exponent,
unsigned long long modulus) {
unsigned long long result = 1;
while (exponent) {
if (exponent & 1) {
result = result * base % modulus;
}
exponent = exponent >> 1;
base = base * base % modulus;
}
return result;
}