Я подумал, что для подсчёта количества решений необязательно вычислять значение y, и заменил 11-12 строки на строку:
if (x * n) % (x - n) == 0:
n = 1000, solutions: 25, time is 0.000
n = 2000, solutions: 32, time is 1.448
n = 3000, solutions: 74, time is 3.853
n = 4000, solutions: 39, time is 7.223
n = 5000, solutions: 32, time is 11.565
n = 6000, solutions: 95, time is 16.873
n = 7000, solutions: 74, time is 23.113
n = 8000, solutions: 46, time is 30.325
n = 9000, solutions: 123, time is 38.495
n = 10000, solutions: 41, time is 47.625
n = 11000, solutions: 74, time is 57.705
n = 12000, solutions: 116, time is 68.748
и второй:
n = 1000, solutions: 25, time is 0.000
n = 2000, solutions: 32, time is 0.783
n = 3000, solutions: 74, time is 2.078
n = 4000, solutions: 39, time is 3.908
n = 5000, solutions: 32, time is 6.263
n = 6000, solutions: 95, time is 9.140
n = 7000, solutions: 74, time is 12.548
n = 8000, solutions: 46, time is 16.473
n = 9000, solutions: 123, time is 20.935
n = 10000, solutions: 41, time is 25.910
n = 11000, solutions: 74, time is 31.405
n = 12000, solutions: 116, time is 37.428
n = 13000, solutions: 74, time is 43.965
n = 14000, solutions: 95, time is 51.035
n = 15000, solutions: 95, time is 58.618
n = 16000, solutions: 53, time is 66.713
Почему так произошло?