Consider the following statement:
for any $a < b \in \mathbb{N}$, one of the following holds:
- $\gcd(a,b) = 1$.
- there is a $a < x < b$ such that $\gcd(a,x) = \gcd(x,b) = 1$.
- there are $a < x < y < b$ such that $\gcd(a,x) = \gcd(x,y) = \gcd(y,b) = 1$.
Is this statement true?
Motivation:
I found a variant of this problem in one of the recent algorithms competitions.
Consider the following problem:
Input: two integers $a$ and $b$ where $a \lt b$.
Output: smallest number $l$ such that there are integers $a = x_0 < x_1 < x_2 < \ldots < x_l < x_{l+1} = b$ such that all consecutive integers in the list are co-prime: $\gcd(x_i, x_{i+1}) = 1$ for $i=0,\ldots, l$.
Examples:
$a = 7, b = 13$: $\gcd(a,b) = 1$, therefore $l = 0$.
$a = 10, b = 12$: $\gcd(a,b) = 2 \neq 1$, therefore $l \geq 1$. Let the sequence be $10, 11, 12$. $\gcd(10, 11) = 1, \gcd(11, 12) = 1$.
$a = 2184, b = 2200$: There is no $a< x < b$ such that $\gcd(a,x)=\gcd(x,b)=1$. However, we can find $2$ integers that satisfy this problem.
There is a reference algorithm that algorithms are evaluated against. That algorithm assumes that
There is always an $l$ that satisfies the condition.
$l\leq 2$.
I don't see why they are true.
I have a polynomial time algorithm that does not assume either of them. I am not losing out on the asymptotic performance compared to the reference algorithm, but I could get the performance constants much lower if I can understand and prove the validity of the assumptions.