Note that a and n must be positive integers such that a < n and GCD(a,n) = 1 where n must be the product of two distinct odd primes.

Also note that this implementation only works on modern browsers. If it takes more than 1 second to calculate for n = 4699, then you're not using a modern browser.