Getting the modulus of a number can be easily done without the modulus operator or divisions, if your operand is a power of 2. In that case, the following formula holds:
int mod31(int a){ while(a >= 31) { a -= 31; } return a; };
It works if a > 0, but I doubt it will be faster than % operator.
a > 0
%