Actually Welcome to the Concept of the function.
to get the inverse of the function,
let's consider that y is the function of m
hence, y = m
now, we know that m = 40g
hence, relatively, y = 40g
but to get inverse, we need gallon of gas as function of distance, hence
g = y/40,
since we know that y = m, replace it
hence the new inverse function is,
====> g = y/40