a number n as pa+qb

127 Views Asked by At

How can we express a number $n$ as $pa+qb$ where $p \geq0$ and $q \geq 0$ and $p$ and $q$ can't be fraction. In contest I got a puzzle as if we can express $c$ as sum of $a$ and $b$ in form $pa+qb$. Suppose $a$ is $3$ and $b$ is $4$ and $c$ is $7$ so we can express $7$ as $3+4$. Suppose $a$ is $4$ and $b$ is $6$ and $c$ is $15$ but we can't express $15$ as sum of $4 \cdot p+6 \cdot q$.

NOTE: $p$ AND $q$ CAN'T BE FRACTIONS.

I came up with an approach to take $\gcd$ of $a$ and $b$ and check if their $\gcd$ leaves zero as remainder when $\gcd$ divides $c$. Is there any general method to check this ?

1

There are 1 best solutions below

4
On

If $a,b$ are fixed natural numbers, then the set of all integers $n$ which can be written in the form $n=pa+qb$ for integers $p$ and $q$ is precisely the set of multiples of the greatest common divisor of $a$ and $b$. So $n$ can be written in the desired form if and only if $n$ is divisible by $\gcd(a,b)$.