To determine how many gallons of paint the painter needs, we first need to calculate the total area of the four walls of the room.
Since the room is shaped like a cube with each side measuring 20 feet:
- The area of one wall (which is a square) is \(20 \text{ ft} \times 20 \text{ ft} = 400 \text{ square feet}\).
Since there are 4 walls:
- The total area of the four walls is \(4 \times 400 \text{ square feet} = 1600 \text{ square feet}\).
Next, we know that one gallon of paint covers 400 square feet. To find out how many gallons the painter needs, we divide the total wall area by the coverage area of one gallon: \[ \text{Number of gallons} = \frac{1600 \text{ square feet}}{400 \text{ square feet/gallon}} = 4 \text{ gallons}. \]
Therefore, the painter should buy 4 gallons of paint.