Independently corrected explanation.
After allocating 3/8 of the total to David, 5/8 of the total remains. David takes 15 additional sweets from that remainder, leaving 25 for Tom.
Therefore 5/8 of the total = 25 + 15 = 40 sweets. One eighth = 40 ÷ 5 = 8 sweets, so the total = 8 × 8 = 64 sweets.
Check: David gets 3/8 × 64 + 15 = 39 sweets and Tom gets 64 − 39 = 25 sweets. Fractions here multiply the total; they are not added directly to counts.