Problem #365
Watch your Enemy
In geometry, a tesseract or 4-cuboid is a four-dimensional hypercuboid, analogous to a two-dimensional rectangle and a three-dimensional cuboid. We have a Tesseract with dimensions a, b, c, and d.
Bob and Alice are playing a game with the Tesseract. In one move, a player can perform the following action:
They choose one dimension s out of the four of the Tesseract. They change the dimension to i units. This move is only allowed if:
gcd(s, s - i) = s - i and i < s and i > 0
For example, they can change the dimension of length 8 to a dimension of length 7, 6 or 4.
Both players are smart, so it is assumed they play optimally. The player who cannot perform a move loses.
Let F(n) indicate the number of sets of dimensions (a, b, c, d) where 1 \leq a, b, c, d \leq n such that Alice wins if Bob starts the game. Two sets are considered different if any one of the dimensions is not the same in both sets. For example, (1,2,1,1) and (2,1,1,1) are different sets.
Find F(324325346214122)\mod 987654321.