Clear pattern for mods starting with (f-1).
1,3,5,7
If (f-1) mod 8 = 1, Then (n-1) mod 8 = 3, (2d-1)(n-1) = 5. nn mod 8 = 0. Total mods = 9
If (f-1) mod 8 = 3, then (n-1) mod 8 = 3, (2d-1)(n-1) = 3, nn mod 8 = 0. Total mods = 9
If (f-1) mod 8 = 5, then (n-1) mod 8 = 3, (2d-1)(n-1) = 1, nn mod 8 = 0. Total mods = 9
If (f-1) mod 8 = 7, then (n-1) mod 8 = 3, (2d-1)(n-1) = 7, nn mod 8 = 0. Total mods = 17
So let's test.
Because if this idea is correct, we can iterate (n-1) based on the mod of (f-1)