What is the time complexity for Miller Rabin Primality Test?
Here is the algorithm from wikipedia page.
write n − 1 as 2^r·d where d is odd.
WitnessLoop: repeat k times: //runs k times.
{ pick a random integer a in the range [2, n − 1]
x ← a^d mod n if x = 1 or x = n − 1 then continue WitnessLoop repeat r − 1 times: //r=O(logn) { x ← x^2 mod n //TC=O(logn) if x = 1 then return composite if x = n − 1 then continue WitnessLoop } return composite
}
return probably prime
According to me the worst case time complexity would be O(k*(logn)^2)? But the wikipedia page mentions it as
O(k*(logn)^3). Can anyone help me out?
https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test