TITLE: A nice and hard colouring problem
QUESTION [10 upvotes]: This question is a generalization of a problem recently appeared in a Italian mathematical competition. 

$A$ and $B$ are two coprime integers, both greater than $2$. A
  non-constant colouring  $$ c:I=\{1,2,3,\ldots,n\}\mapsto \{0,1\}$$ has the
  following properties:

if $u,v\in I$ and $|u-v|=A$, $c(u)=c(v)$;
if $u,v\in I$ and $|u-v|=B$, $c(u)=c(v)$.

What is the maximum value of $n$, as a function of $A$ and $B$?

In the original problem, $A=11$ and $B=16$. If we assume that $c(a)=1$ (let we say that $a$ is black) then $a+11,a+22,a+33,\ldots$ are black, too. By assuming that $n>22$, then $a+6,a+17,a+28,\ldots$ are black, too. We may continue this way till a number in the range $a,\ldots,a+10$ is still white, then deduce the maximum value of $n$.
We may also notice that if $AB_1-BA_1=1$, with $1\leq A_1<A$ and $1\leq B_1<B$, and $k,k+1$ are the first numbers with different colours, we must have $n<k+AB_1$. So the answer to the generalization above should be dependent on Bézout's identity and the length of the Euclidean algorithm for $\gcd(A,B)=1$. I am just wondering how.
We may also notice that if $n$ is maximal, $c(A)$ and $c(B)$ have to be different (so we may assume $c(\min(A,B))=1$ WLOG), otherwise we may introduce and element $0$ and give to it the same colour of $A$, then re-indexing the elements of $I$, contradicting the maximality of $n$. That leads to:

$$ \max n\leq A+B-1.$$

REPLY [2 votes]: Assume $2\leq A<B$. Then $B=qA+r$ with $q\geq1$, $\>1\leq r\leq A-1$, and $r$ prime to $A$. 
Imagine an "abstract" regular $A$-gon with vertex set $V\sim{\mathbb Z}/A$. If we draw the $A$ chords $\{k,k+r\}$ we obtain a cyclic graph $\Gamma$. Omitting an edge from $\Gamma$ leaves a connected graph $\Gamma'$, but if we omit $\geq2$ edges from $\Gamma$ the resulting graph on $V$ is no longer connected.
The set $[n]:=\{1,2,\ldots, n\}$ splits into $A$ remainder classes modulo $A$. All members of the same class are colored with the same color; hence each class has its color. Some of these classes are related by a $B$-jump and  therefore are assigned the same color. The possible $B$-jumps are $$1\to1+B, \quad 2\to 2+B, \quad \ldots, \quad n-B\to n\ .$$
The first $A$ of these jumps lead to different edges of $\Gamma$.
If $n-B\leq A-2$, or $n\leq A+B-2$, then not all classes modulo $A$ are connected by $B$-jumps, hence a  nonconstant coloring of $[n]$ of the desired kind is possible. If, however, $n-B\geq A-1$, or $n\geq A+B-1$, then $\geq A-1$ different chords in $\Gamma$ are realized, which then implies that all remainder classes modulo $A$ will get the same color.