I have been thinking about this problem a lot lately. Given a $p$-liter and a $q$-liter with $p < q$, there is an algorithm involving $p$ and $q$ which outputs a $c$ for each set of operations inside of the algorithm.
For an example, consider a $4$-liter jug and a $9$-liter jug, where we need $6$ liters.
- Fill up the smaller jug. (In this case, the $4$-liter jug.)
- Slowly pour the smaller jug into the larger jug until either the larger jug is full or the smaller jug is empty.
- If the larger jug is full, empty it out and put the remaining contents of the smaller jug into the larger jug.
- Measure and record $c$, the number of liters in the larger jug. (In this case: $4$ liters in the $9$-liter jug.)
- Repeat until the desired $c$ is acquired.
Running this algorithm for this example outputs the following values for $c$: $4, 8, 3, 7, 2, 6, 1, 5, 0$. Those with a keen eye will see that these are the elements of $Z9$, the group of integers modulo 9.
In general, this algorithm will eventually produce all elements of $<p>$ inside $Zq$, the group of integers modulo $q$.
For the layperson (who knows about modular arithmetic), the possible amounts of water which can be obtained are $1 * p$ $mod$ $q$, $2 * p$ $mod$ $q$, $3 * p$ $mod$ $q$, ..., $q * p$ $mod$ $q$.
The number of operations required to find $c$ is always less than $4*q$. (This is because we have four steps to check each integer up to q, maximally).