There are 40 students in a Grade 8 class. The teacher gave each Grade 8A student 5 counters and each Grade 8B student 3 counters. After distributing the counters, the teacher realized that the Grade 8A students had 128 more counters the Grade 8B students. Write and solve an equation to determine the number of Grade 8A students in the class

Let the number of Grade 8A students be a.

Then the number of Grade 8B students is 40 - a.

The total number of counters distributed to Grade 8A students is 5a.
The total number of counters distributed to Grade 8B students is 3(40 - a) = 120 - 3a.

According to the information given, we have the equation:
5a = 120 - 3a + 128.

Simplifying the equation gives:
8a = 248.

Dividing both sides by 8 gives:
a = 31.

Therefore, there are 31 Grade 8A students in the class.