See these two submissions:
The only difference between the two being that A uses a hand-made function I stole from here:
int add(int a, int b) {
int res = a + b;
while (res >= MOD) res -= MOD;
while (res < 0) res += MOD;
return res;
}
This function is easy to understand. I am just not sure, why using this only, the running time of the program went down from 936ms to 561ms. That difference is bigger than expected. Can anyone help with, why is this happening? Why exactly is this function faster than simply using %MOD
?