I am just testing a simple maths equation here.
Lets say i want to perform (12345678901234567890^9876543219876543) mod 12345678975313579, wolframalpha output "8676260740635552". However, i am getting an output of "0" in my program. Much help appreciated, thank you!
1 2 3 4
unsignedlonglong hi = 0;
hi = pow(12345678901234567890.0,9876543219876543);
cout << hi%12345678975313579;
return 0;
The value returned by pow is probably too big for double to handle so it returns infinity. I think it's undefined what will happen when you convert infinity to an integer but in your case it looks like hi got the value 0.
Exponentiation and modulo on big numbers can be computed more efficiently if it's done as one operation. That's why some Big Number libraries have functions for doing exponentiation and modulo together. Take a look at the GMP library, it has the function mpz_powm that does what you want: https://gmplib.org/manual/Integer-Exponentiation.html