Let the number of rows and columns be r and c respectively. Although both r and c can be any quantity, we know that each row must contain exactly 3 boys and each column exactly 5 girls. Therefore, we get 3r+5c=rc. Rearranging, rc-3r-5c=0. Then
r(c-3)-5c=0
r(c-3)-5c+15=15
r(c-3)-5(c-3)=15
(r-5)(c-3)=15
So now we can substitute two integers that multiply to 15 to find (r-5) and (c-3).
r-5=1, r=6 and c-3=15, c=18
r-5=3, r=8 and c-3=5, c=8
r-5=5, r=10 and c-3=3, c=6
r-5=15, r=20 and c-3=1, c=4
With the values of r and c, multiply them to find the possible sizes and add to find the answer.
6 x 18 = 104
8 x 8 = 64
10 x 6 = 60
20 x 4 = 80
Hence, the sum of all possible sizes is 104+64+60+80=312