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?

5

1

4

6

Since the room is shaped like a cube, each wall is a square with sides measuring 20 ft. Therefore, the area of each wall is 20 ft x 20 ft = <<20*20=400>>400 sq ft.

Since there are 4 walls in the room, the total area to be painted is 4 walls x 400 sq ft/wall = <<4*400=1600>>1600 sq ft.
Each gallon of paint can cover 400 sq ft, so the painter should buy 1600 sq ft รท 400 sq ft/gallon = <<1600/400=4>>4 gallons of paint. Answer: \boxed{4}.