A painter is going to paint a room shaped like a cube, with square walls that are 20 ft. on each side. A gallon of paint can be used to cover 400 square feet. How many gallons of paint should the painter buy if he is going to paint the four walls of the room?

1 gallon

6 gallons

4 gallons

5 gallons

The total area of the four walls of the room is 4 * (20 ft * 20 ft) = 4 * 400 ft^2 = <<4*(20*20)=1600>>1600 ft^2.

A gallon of paint can cover 400 ft^2, so the painter will need 1600 ft^2 / 400 ft^2/gallon = <<1600/400=4>>4 gallons of paint.
Therefore, the painter should buy 4 gallons of paint. Answer: \boxed{4}.