Answer: Let's call the number of cookies Trey has "x".
Gerald has 8 less cookies than Trey, so he has x - 8 cookies.
Trey bought five times the number of cookies as Gerald, so he has 5 * (x - 8) = 5x - 40 cookies.
Combining these two equations, we have:
x + (x - 8) = 5x - 40
Simplifying, we get:
2x - 8 = 5x - 40
Solving for x, we find:
3x = 32
And finally, x = 10.
So Trey has 10 cookies and Gerald has 2 cookies.
Explanation: