e.g. given two numbers $5$ and $6$ the maximum number is $19$, as after $19$ each number can be formed using equation $5n+6m$ 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.


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 $ 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


Let $\let\leq\leqslant\let\geq\geqslant m\in\mathbb N$ and $\gcd(a,b)=1$. Bézout already gives us $x,y$ with $xa+yb=m$, but they can be negative. Because we want to control $x$ and $y$ simultaneously we might devise a tool that links those two terms. One approach to make the terms $xa$ and $yb$ look similar is by making them both almost multiples of $\color{blue}{ab}$.

Here's how: write $x=q_1b+r_1$ and $y=q_2a+r_2$ with $0\leq r_1<b$ and $0\leq r_2<a$.
We have $$\begin{align*}n=xa+yb&=(q_1\color{blue}{ab}+r_1a)+(q_2\color{blue}{ab}+r_2b)\\ &=(q_1+q_2)\color{blue}{ab}+r_1a+r_2b.\end{align*}$$

Most of the work has been done.

Observe $r_1a+r_2b\leq a(b-1)+b(a-1)$ so for $n>a(b-1)+b(a-1)$ we have $q_1+q_2>0$. (This shows that a maximum exists.) This should allow for smaller $n$ to be be written as wanted, because $$\begin{align*}n-ab=(q_1+q_2-1)ab+r_1a+r_2b\qquad&\text{with }q_1+q_2-1\geq0\\&\text{if }n>a(b-1)+b(a-1).\end{align*}$$

Indeed: let $g=a(b-1)+b(a-1)-ab$ and $n>g$. Then $n+ab$ can be written as $$n+ab=(q_1+q_2)ab+r_1a+r_2b\qquad\text{with }q_1+q_2\geq1$$ hence $$n=(q_1+q_2-1)ab+r_1a+r_2b\qquad\text{with }q_1+q_2-1\geq0.$$

So everything $>g$ can be written with positive coefficients (e.g. by taking together $a\cdot r_1$ and $a\cdot b(q_1+q_2-1)$).

$g=ab-a-b$ is a lower bound
Indeed, if $ab-a-b=ax+by$ then $a\mid y+1$ but $ax+by\geq0+b(a-1)>g$, contradiction.

Note: this technique allows to prove in general that the largest not representable number is $$g(a_1,\ldots,a_n)\leq(n-1)a_1\cdots a_n-(a_1+\cdots+a_n).$$ This upperbound is exact for $n=2$, but weak for $n>2$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.