# Given 2 numbers a and b, what is the maximum number which can not be formed using n*a + m*b

e.g. given two numbers 5 and 6 the maximum number is 19, as after 19 each number can be formed using equation 5*n+6*m by putting different (non-negative) values for n and m.
Such number is not possible for 4 & 6.
I am not sure how to go-forward. The only thing I have till now is that the number is possible only if the given numbers are pseudo-prime. Any help is appreciated.

-
I just know this is a repeat, but I can't seem to find it... –  Arturo Magidin Feb 8 '11 at 16:50
"if the given numbers are pseudo-prime"----you certainly mean relatively prime, as the word pseudo-prime has a different meaning (and is a noun). –  Eric Naslund Feb 8 '11 at 17:11
Arturo is right. This is a special case of math.stackexchange.com/questions/8241/… –  Mike Spivey Feb 8 '11 at 17:45

Here's an excerpt from one of my old sci.math posts which explains a geometric viewpoint.

Notice that we may normalize any representation $\rm\ N\ =\ P\ X + Q\ Y\$ so that $\rm\ 0 \le X < Q\$ by adding a certain integral multiple of $\rm\ (-Q,P)\$ to $\rm\:(X,Y)\:.\$ From this observation follows this

LEMMA $\rm\ \ N = P\ X + Q\ Y\$ for some integers $\rm\ X,Y \ge 0\$ iff its normalization has $\rm\: Y \ge 0\:$.

Proof $\rm\ \ \ X,Y \ge 0\$ implies that normalization requires addition of $\rm\:(-Q,P)\:$ zero or more times,$\$ and this preserves the condition $\rm\: Y \ge 0\:.\$ Conversely if the normalization has $\rm\: Y < 0\:,\$ then $\rm\:N\:$ has no representation with $\rm\ X, Y \ge 0\:,\$ because to shift $\rm\: Y > 0\:$ requires adding $\rm\ (-Q,P)\$ at least once, which shifts $\rm\: X < 0\:.\$ Finally, since $\rm\ X\ P + Y\ Q\$ is increasing in both $\rm\: X,Y\:,\$ it is clear that the largest non-representable number $\rm\: N\:$ has normalization $\rm\: (X,Y)\ =\ (Q-1,-1)\:,\:$ therefore $\rm\ N\ =\ PQ - P - Q\:.\quad\quad$ QED

Notice that the proof has a vivid geometric picture: representations of $\rm\:N\:$ correspond to lattice points $\rm\:(X,Y)\:$ on the line $\rm\ N = P\ X + Q\ Y\$ with negative slope $\rm = -P/Q\:.\$ Normalization is achieved by shifting forward/backward along the line by integral multiples of vector $\rm\:(-Q,P)\:$ until you land in the normal strip where $\rm\ 0 \le X < Q-1\:.\$ From this viewpoint, the proof becomes crystal clear.

In case you're interested, the class I'm teaching is linear algebra, but as you can see I like to give puzzles to the class which are not necessarily related to the material (in an obvious way).

Here the underlying linear structure is a $\mathbb Z$-module, a generalization of a vector space; i.e. here the scalars are the integers so have only the structure of a ring, not a field. Unless you've already taught some module theory, it might be tricky to precisely explain the relationship to vector spaces.

Finally it should be mentioned that there has been much written on this classical problem. To locate such work you should ensure that you search on the many aliases, e.g. postage stamp problem, Sylvester/Frobenius problem, Diophantine problem of Frobenius, Frobenius conductor, money changing, coin changing, change making problems, h-basis and asymptotic bases in additive number theory, integer programming algorithms and Gomory cuts, knapsack problems and greedy algorithms, etc.

-
The general formula for coprime $a$ and $b$ is that you can make all numbers from $(a-1)(b-1)$ onwards but there are numbers before it that cannot be made as such positive integer multiples.
Start by observing that for coprime $a$ and $b$ we can write $1 = na + mb$ for some $n,m \in \mathbb{Z}$. So for an integer $x$ we have $x = nxa + mxb$. Now substract or add $0 = a*b - b*a$ to both sides of the equation to make coefficients positive