I'm working on a primality test and have written a recursive function that returns the value of the function\$b^{q-1} \bmod q\$where \$3<= q <= 32000\$Is there any way to speed up my function? It works, but takes a while to return the answer as \$q\$ approaches 32000.Variables: pow = \$q-1\$ mod = \$q\$ b is a variable ranging from \$1 < b < q \$If q is prime, then b will be = to q if not, b will be a strong feature of non-primality. See MillerRabin primality test.public int fF(int q)    {        int b = 2, v = 0;        while(b < q)        {            v = operate(b, q-1, q);            if (v != 1)                break;            b++;        }        return b;    } int operate(int b, int pow, int mod)    {        if (pow == 2)           return (b * b) % mod;        return (pow % 2 != 0) ? (b * operate(b, pow - 1, mod)) % mod : (operate(b, pow / 2, mod) * operate(b, pow / 2, mod)) % mod;    }
Miller-Rabin Recursive Primality Test
c#;algorithm;recursion;primes