A
A
Alexey Kuzmin2013-04-04 21:47:39
Programming
Alexey Kuzmin, 2013-04-04 21:47:39

Prompt algorithm

It is necessary to find the maximum possible number that cannot be obtained by combining two given numbers using summation operations. For example, the numbers 2 and 5 are given - the answer is 3, the remaining natural numbers can be obtained by combining 2 and 5 (21 = 5 + 5 + 5 + 2 + 2 +2). If the answer is infinity, this should also be reported.
The numbers are all natural.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
mayorovp, 2013-04-05
@xHellKern

Here is the complete solution.
Let the initial numbers be a and b.
1. Obviously, if the numbers are not coprime, the answer is infinity.
2. It is known that any number m can be represented as m = ka+lb with coprime a and b.
For m not to be decomposable, one of two conditions must be satisfied: k<0 or l<0.
Note that (k+b)a+(la)b = ka+lb = (kb)a+(l+a)b. This implies that for an indecomposable m, there must exist k and l such that k<0, l<a or k<b, l<0 (otherwise, one can find an expansion using one of these formulas).
Since we know the upper limits for both k and l, and these limits are independent,
we can take these variables to the maximum.
m = (-1)a+(a-1)b = (b-1)a+(-1)b = ab-ab.
Therefore, for coprime a and b, the answer is ab-ab, and for those having common divisors, infinity.

F
FilimoniC, 2013-04-04
@FilimoniC

As usual, 2 ways - Blind enumeration and functional analysis.
I think you need to write a system of simple equations

F
fader44, 2013-04-04
@fader44

Infinity will be when they are not coprime, in all other cases the answer is finite. Then google Diophantine equations, I won’t deduce the exact solution before I fall asleep =)

O
onehell, 2013-04-04
@onehell

I can’t answer myself (I’m an applied programmer, not a mathematician).
To be honest: do you need it for some practical tasks?

F
FilimoniC, 2013-04-04
@FilimoniC

By condition, both numbers must be present in the expression at least 1 time?
What is the original system of equations?
aX + bY > Z a
E [1;+inf]
b E [1;+inf]
X > 0
Y > 0
X = *
Y = *
I can decide.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question