Solution:
We claim that (a,b) is spicy if and only if both gcd(a+1,b−1)=1 and gcd(a−1,b+1)=1.
To prove the claim, we note that
gcd(a+b,ab+1)=gcd(a+b,b(−b)+1)=gcd(a+b,b2−1)
Hence, we have
gcd(a+b,ab+1)=1⟺gcd(a+b,b2−1)=1⟺gcd(a+b,b−1)=1 and gcd(a+b,b+1)=1⟺gcd(a+1,b−1)=1 and gcd(a−1,b+1)=1,
proving the claim.
Thus, n works if and only if all following four conditions hold:
- gcd(n+1,98)=1, or equivalently, n is neither −1(mod2) nor −1(mod7);
- gcd(n−1,100)=1, or equivalently, n is neither 1(mod2) nor 1(mod5);
- gcd(n+1,100)=1, or equivalently, n is neither −1(mod2) nor −1(mod5); and
- gcd(n−1,102)=1, or equivalently, n is neither 1(mod2), 1(mod3), nor 1(mod17).
Thus, there are 1,2,3,6,17 possible residues modulo 2,3,5,7, and 17, respectively. The residues are uniformly distributed within {1,2,…,2024!}. Hence, the answer is
21⋅32⋅53⋅76⋅1716=59596