There are 4 quarts in a gallon and 4 cups in a quart, so 16 cups in a gallon. So 3.5 gallons is 16 times 3.5, or 56 cups total. That 56 cups is what needs to poured into the 1/3 cup measure as many times as possible. So 56 divided by 1/3 is 168, with zero left over.
You just multiply the numerators of the fractions and the denominators of the fractions together, and then reduce the fraction to simplify it from that point on.