two squares problem in O(sqrt(n)) time