Found a pattern that can be used to improve performance for f mod 8 = 5.
Pic attached shows the original and revised test cases with similar 50% less iterations.
This improvement comes from verifying that the d for the current n0 and XPN is a valid entry.
From nn-1 + 2d(n-1) + f = XPN, and given n0, f and XPN, we can test if (XPN - (nn-1 + f)) mod 2(n-1) == 0. If so, then the n+4 jumping works properly.