Stop looking after reaching sqrt(n)