hackerrank time complexity Primality problem solution in python