It loops forever on long numbers. And sometimes produces false results. I have not analyzed why exactly this is wrong but for the number -810873502888/74-556227/1 (the last number of the output.txt) it gives 62 results while the number of correct results is 18.