To determine the smallest number of gallons of gas needed for the total cost to be a whole number of dollars at a price of $3.15 per gallon, we need to find the smallest integer \( n \) such that the total cost \( 3.15n \) is a whole number.
First, let's express \( 3.15 \) as a fraction:
\[ 3.15 = \frac{315}{100} \]
Next, the total cost in dollars for \( n \) gallons of gas is:
\[ \text{Total cost} = 3.15n = \frac{315}{100}n \]
For \( \frac{315n}{100} \) to be a whole number, \( 315n \) must be divisible by \( 100 \). Therefore, we need to find the smallest \( n \) such that \( 315n \) is a multiple of \( 100 \).
To do this, we can find the prime factorization of \( 100 \) and \( 315 \):
- \( 100 = 2^2 \times 5^2 \)
- \( 315 = 3^2 \times 5 \times 7 \)
Next, we want \( 315n \) to include at least \( 2^2 \times 5^2 \). However, \( 315 \) itself contains only one factor of \( 5 \) (from \( 5^1 \)). Thus, we need to add another factor of \( 5 \) and also the necessary factors of \( 2 \).
We currently have:
- Factors of \( 2 \): \( 0 \) (we need \( 2^2 \))
- Factors of \( 5 \): \( 1 \) (we need \( 5^2 \))
To make \( 315n \) divisible by \( 100 \):
- Introduce \( 2^2 \) by multiplying \( n \) by \( 4 \).
- Introduce an additional factor of \( 5 \) by multiplying \( n \) by \( 5 \).
Therefore, the smallest \( n \) must contain \( 4 \) and \( 5 \) to cover both deficiencies:
\[ n = 4 \times 5 = 20 \]
Verification:
- Calculate \( 3.15 \times 20 \): \[ 3.15 \times 20 = 63 \]
Since \( 63 \) is indeed a whole number, the smallest number of gallons of gas you would have to buy for the total price to be a whole number is:
\[ \boxed{20} \]