my goal on this code is to make exponential operations without pow(). It works for evey value a^b which b <= 30. I'm aware that I should be using x % 1000000007 to prevent integers overflows.
#include <stdio.h>
int main(void) {
int i, a, b, rst;
rst = 1;
scanf("%d %d", &a, &b);
for (i = 0; i < b; i++){
rst = rst * a;
if( b == 0){
rst = 1;
}
}
printf("%d\n", rst % 1000000007);
return 0;
}
Why does it returns a "0" for example on "2^40 % 1000000007" even though I'm using % 1000000007?