The best method known to me is of order sqrt(n). I read about Fermat’s Primality Test and Miller-Rabin Primality Test. They operate in O(log(n)) time, but a major drawback is that they fail sometimes as well. Can you help me out?
If possible provide an algorithm and code in python ( Even algorithm will be sufficient).