Each entry a

_{ij}in the exponentiation table with i rows and j columns of Z

_{n}when n is the product of 2 distinct primes can be generated as follows:

a

_{ij}= [(j - 1)(a_{i-1}+ a_{i-2}+ a_{i-3})] + a_{i-3 }mod nBelow is an algorithm for finding the order of any element of the exponentiation table of Z

_{n}when n is the product of 2 distinct primes. It can easily be modified to generate the entire table recursively.

It's also fast.

```
/* -------------------------------------------------
This content is released under the GNU License
http://www.gnu.org/copyleft/gpl.html
Author: Marina Ibrishimova
Version: 1.0
Purpose: Find the order of any a mod n for n = p*q where p,q > 2
---------------------------------------------------- */
function find_order(n, a)
{
var anot = 1;
var aa = a;
var aaa = a*a;
var coef = a - 1;
var index = 0;
var order = 2;
//added bonus
var bingo = "a divides n";
while(index != 1)
{
if (index === a) {return bingo;}
index = (coef*(anot + aa + aaa) + anot) % n;
anot = aa;
aa = aaa;
aaa = index;
order = order + 1;
}
return order;
}
```

**Example:**The algorithm described in this post here and implemented with a worker finds it in 1:49 min whereas the algorithm implemented in Life of Phi and featured in Finding Phi Faster finds the order of 2 mod 915313319 in 2:20 min. The worker slows things down a bit, like quite a bit.

The above algorithm returns the correct answer for the order of 2 mod 915313319 in less than 20 seconds and only one "unresponsive script" nudge in the ribs required to return the correct result! What's more impressive is that find_order(n, a) can find the order of any element a of Z

_{n}if GCD(a, n) = 1 or find a zero divisor of Z

_{n}, and in particular it can find the order of 4 mod n much faster.

Indeed, in a web console find_order(n, a) returns the order of 4 mod 915313319 in less than 10 seconds!

**For faster JS results, try find_order(n, a) in a web console.**

Below are a few slower JS implementations.

The algorithm described in this post with a worker:

The algorithm described in Life of Phi with a worker: