Let $p{}$ and $q{}$ be two coprime positive integers. A frog hops along the integer line so that on every hop it moves either $p{}$ units to the right or $q{}$ units to the left. Eventually, the frog returns to the initial point. Prove that for every positive integer $d{}$ with $d < p + q$ there are two numbers visited by the frog which differ just by $d{}$. Nikolay Belukhov
Problem
Source: 42nd International Tournament of Towns, Junior A-Level P7, Spring 2021
Tags: combinatorics, Combinatorial Number Theory, Tournament of Towns, Kvant
19.02.2023 11:15
Let's call a hop to the right a right hop, and to the left a left hop. By Bézout's Theorem, $\exists a, b\in\mathbb Z$ s.t. $ap-bq=d$. We can make $a, b$ positive simply. Suppose the frog uses $x$ right hops and $y$ left hops in total, and after the $x+y$ hops that returning to the initial point, it does the $x+y$ hops in the same way again and again. Let's call consecutive $a+b$ hops a long jump, and $L_i$ the long jump that contains the $i, i+1, \dots, i+a+b-1$-th hops. Suppose $L_i$ contains $c_i$ right hops and $a+b-c_i$ left hops. Since hopping $(a+b)(x+y)$ times will return to the initial point, there exist a long jump $L_r$ that doesn't move to the left, and a long jump $L_l$ that doesn't move to the right. Since $L_i=L_{i+x+y}$, WLOG suppose $l\leq r$. If $c_r<a$, then $c_rp-(a+b-c_r)q\leq(a-1)p-(b+1)q=d-p-q<0$, contradicts to that $R$ doesn't move to the left. $\therefore c_r\geq a$. Similarly, $c_l\leq a$. $\because|c_i-c_{i+1}|\leq1$. $\therefore a\in\{i|c_l\leq i\leq c_r, i\in\mathbb Z\}\subseteq\{c_l, c_{l+1}, \dots, c_r\}$. $\Rightarrow\exists$ a long jump $L_k$ s.t. $c_k=a$, and that long jump will move $ap-bq=d$ to the right. The $2$ numbers before and after $L_i$ are visited by the frog, and their difference is $d$.
19.02.2023 11:47
i watched the sol without trying lol, i can tell it is a good problem
23.08.2023 03:48
local brain strikes again We clearly need $kq$ rightwards hops and $kp$ leftwards hops for some $k \geq 1$. Represent each possible series of hops in the obvious way using a string of length $k(p+q)$ consisting of $P$ and $Q$. Call a point a "$P$-pivot" if the frog switches directions from left to right on it, and define a "$Q$-pivot" similarly. Define a "$P$-block" as a maximal substring of rightwards moves, and define a "$Q$-block" similarly. Now, fix $k$ and $d$, and suppose the problem statement was false for some series of hops. Consider the lexicographically (where $P$ comes before $Q$) minimal string such that there do not exist two numbers visited by the frog which differ by $d$. First suppose that this string contains at least one $P$-pivot. Then for any $P$-pivot at $x$, if we flip the two adjacent characters in the string (from $QP$ to $PQ$), the numbers visited by the frog are unchanged, except one occurrence of $x$ is replaced by one occurrence of $x+p+q$. By minimality, it follows that $x+p+q\pm d$ (where the sign is fixed) must be visited by the frog in our original string. Let the $Q$-block to the left of $x$ (in the string) have size $a$, so $x+q,\ldots,x+aq$ were all visited by the frog as well. Therefore, immediately before visiting $x+p+q\pm d$, the frog must have visited $x+p+2q \pm d$ (treating moves cyclically, so if $x+p+q\pm d$ was the starting position, then the position before it is also the second-to-last), since if it visited $x+q\pm d$ this contradicts the fact that the problem condition isn't true for this string. Then before this, it must have visited $x+p+3q \pm d$, and so on, all the way up to $x+p+(a+1)q \pm d$ (where the sign is the fixed). Likewise, if the $P$-block to the right of $x$ has size $d$, then $x+p+q \pm d,\ldots,x+(b+1)p+q \pm d$ must have all been visited by the frog. Now, the largest number visited by the frog must either be a $Q$-pivot, or be the first position, with the latter only possibly occurring if the first block is a $Q$-block. In any event, we can either find a $Q$-block following it which ends in a $P$-pivot (i.e. is not the rightmost) or a $P$-block preceding it which begins with a $P$-pivot (i.e. is not the leftmost); WLOG the former (the latter is similar). Then if the ending $P$-pivot is $x$ and the $Q$-block has $a$ elements, it is clear that the largest number is $x+aq$, but by our above results $x+p+aq\pm d$ must be visited by the frog too. Since $d<p+q$, we have $x+p+aq\pm d>x+aq$: contradiction. Therefore, it suffices to prove that if there are no $P$-pivots—i.e. the sequence of moves is a single $P$-block followed by a single $Q$-block—then the frog visits two numbers with difference $d$. It is clear that the visited numbers are precisely $ap$ for $0 \leq a \leq kq$ and $kpq-bq$ for $0 \leq b \leq kb$, so it suffices to show the existence of such $a,b$ with $kpq-bq-ap=d \iff ap+bq=kpq-d$. This is just by Chicken McNugget, since $kpq-d>pq-p-q$, so we're done. $\blacksquare$
27.09.2024 05:01
Peak combo. Rename $p$ and $q$ to $a$ and $b$. Let $n$ be the number of total jumps. Denote the frog’s journey as $+a$ written $nb$ times and $-b$ written $na$ times. For each integer $0<d<a+b$, we want to show that there is a contiguous set of numbers written that sum to $d$ or $-d$, since this corresponds to the frogs position changing by $\pm d$. The key idea again here is a ``sliding window''. Let $d=a\cdot k - b \cdot j$ with $j,k$ positive integers and minimal. By modular inverses, $j+k < a+b$. Set up a sliding window of length $j+k$ (so as the window slides it always shows $j+k$ numbers), and let the window cycle around the ends. Thus there are $a+b$ positions of the window, and it could cover a contiguous set of numbers on each end. Let $S$ be the sum of the numbers shown by the window. Then, $S$ is of the form $ma-(j+k-m)b = d+l(a+b)$ for some integer $l$. The sum of the $S$ value for all positions of the window is $j+k$ times the sum of the numbers, or just $0$. Hence the window must show a positive sum at some point and must show a negative sum, since $d+l(a+b) \neq 0$ for al integers $l$. In a slide by $1$, $S$ can only change by $0$ or $ \pm (j+k)$. Thus as $d$ is the smallest positive possible value of $S$, we obtain that $S$ must once be $d$ by discrete IVT. if the window at this point shows a contiguous set of numbers, we are done. if the window ``wraps around'', all numbers hidden by the window sum to $-d$. As said above, this also finishes as the frog's position still changed by $d$. In either case we can conclude. Remark: Here is some motivation, I guess. This claim was in my original solution. Claim: [Reduction to $a+b$ length sequences] The frog will land of two of the same number exactly $a+b$ hops apart at some point. Proof. Suppose the frog jumps $n(a+b)$ times, jumping forward by $a$ a total of $nb$ times, and backward by $b$ a total of $na$ times. The denote the jumps with $nb$ $+$ signs and $nb$ $-$ signs. Split the series of $+$s and $-$s into $n$ groups of $a+b$ signs, grouping the first $a+b$ signs, then the $a+b$ after those, and so on. If any of these groups has $b$ $+$s, we are done since that group sums to $0$. If not, then there must be two consecutive groups, $G_1$ with $<b$ $+$s, and $G_2$ with $>b$ $+$s. This is possible by, say, pigeonhole. Start a ``sliding window'' at $G_1$, leaving only that $G_1$'s $a+b$ signs exposed. Slide this window over to the other group such that $a+b$ numbers are always exposed. When we slide the window one over, the number of $+$s changes by at most $1$. But it started with less than $b$ $+$s and ended with more than $b$, so by discrete IVT we conclude it must be exactly $b$ at some point. $\blacksquare$
18.10.2024 03:22
What a great problem. Extend the sequence of adding $p$ and subtracting $q$ to an infinite periodic sequence. Call an ordered pair $(a, b)$ attainable if there exists $a+b$ consecutive moves that contain $a$ additions and $b$ subtractions. We begin with the following lemma: Lemma: [Discrete IVT, as they call it] Fix $k$. If for some $a < b$, both $(a, k-a)$ and $(b, k-b)$ are attainable, then $(i, k-i)$ is attainable for any $a \leq i \leq b$. Proof: Pan over the sequence with a pan of length $k$. By shifting the pan to the right by one move, we lose or gain at most one addition or one subtraction, hence $a$ and $b$ change by at most $1$. The result follows. $\blacksquare$ By Bezout's lemma, every integer with absolute value less than $p+q$ can be written as $ap - bq$ for some positive integers $a$ and $b$. I claim that if $|ap-bq| < p+q$, then $(a, b)$ is attainable, which will finish the problem. Once again, fix $k = a+b$. Consider the following claim: Claim: There is an attainable pair $(a, b)$ with $b \geq \left \lceil \frac{kp}{p+q} \right \rceil$ and a pair with $a \geq \left \lceil \frac{kq}{p+q} \right \rceil$. Proof: The average of the number of subtractions among any consecutive $k$ moves is $\frac{kp}{p+q}$, as exactly $\frac p{p+q}$ of the moves are subtractions. The other part follows. $\blacksquare$ Now, observe that if $(a, b)$ is a pair with $|ap-bq| < p+q$, then $b \leq \left \lceil \frac{kp}{p+q} \right \rceil$, otherwise \[ap-bq \leq p\left(\frac{kq}{p+q} - 1\right) - q\left(\frac{kp}{p+q} + 1\right) \leq -(p+q)\]as $ap-bq$ strictly decreases as $b$ increases. Similarly, $a \leq \left \lceil \frac{kq}{p+q}\right \rceil$, so the result follows by the claim and the lemma.