.
Let n be that unknown number of grandchildren.
Then the number of cookies C = 4n +2, according to the first part of the condition.
At the same time, C = 5n - 2, from the other part of the condition.
It gives you an equation
4n + 2 = 5n -2,
which gives you the solution n = 4.
Answer. The number of grandchildren is 4.
The number of cookies is 18.
Solved.