A painter is going to paint a room shaped like a cube with square walls that are 20 feet 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

The total area of the four walls of the room is 4 * (20 ft * 20 ft) = 4 * 400 square feet = 1600 square feet.

Since a gallon of paint can cover 400 square feet, the painter needs 1600 square feet / 400 square feet/gallon = <<1600/400=4>>4 gallons of paint. Answer: \boxed{4}.