I am stuck with probably simple question. I got 3 large numbers(A,B,C), all integers and i need to do the following: power A to B and modulo the result by C, and then check if the result is equal to 1. Here's my code:
double power = fmod((pow((double)A,(double)B)),(double)C);
if (power != 1){
printf("Something!\n");
}
And it doesnt work(I tried small numbers, like 17 powered by 28 and moduled by 29). Any suggestions on that?
Try this (in order to avoid arithmetic overflow):
You can further improve the runtime performance with this: