Soln:
Let number of children be x.
Then each student will get 40/x
If there were 2 children less i.e x-2 then each would get 40/(x-2)
According to question
40/(x-2)-40/x = 1
[40*x-40*(x-2)]/[(x-2)x] = 1
(40x-40x+80)/(x^2-2x) = 1
x^2-2x-80 = 0
x^2-(10-8)x-80 = 0
x^2-10x+2x-20 = 0
x(x-10)+2(x-10) = 0
(x-10)(x+2) = 0
Either,
x-10 = 0
x = 10
or,
x+2 = 0
x = -2 (No. of marbles cannot be negative.)
Therefore, required number of marbles is 10.