Determine all integers $n \geqslant 2$ with the following property: for any integers $a_{1}, a_{2}, \ldots, a_{n}$ whose sum is not divisible by $n$, there exists an index $1 \leqslant i \leqslant n$ such that none of the numbers  $$ a_{i}, a_{i}+a_{i+1}, \ldots, a_{i}+a_{i+1}+\cdots+a_{i+n-1} $$  is divisible by $n$. (We let $a_{i}=a_{i-n}$ when $i>n$.) (Thailand) Answer: These integers are exactly the prime numbers.

Solution: Let us first show that, if $n=a b$, with $a, b \geqslant 2$ integers, then the property in the statement of the problem does not hold. Indeed, in this case, let $a_{k}=a$ for $1 \leqslant k \leqslant n-1$ and $a_{n}=0$. The sum $a_{1}+a_{2}+\cdots+a_{n}=a \cdot(n-1)$ is not divisible by $n$. Let $i$ with $1 \leqslant i \leqslant n$ be an arbitrary index. Taking $j=b$ if $1 \leqslant i \leqslant n-b$, and $j=b+1$ if $n-b<i \leqslant n$, we have  $$ a_{i}+a_{i+1}+\cdots+a_{i+j-1}=a \cdot b=n \equiv 0 \quad(\bmod n) $$  It follows that the given example is indeed a counterexample to the property of the statement. Now let $n$ be a prime number. Suppose by contradiction that the property in the statement of the problem does not hold. Then there are integers $a_{1}, a_{2}, \ldots, a_{n}$ whose sum is not divisible by $n$ such that for each $i, 1 \leqslant i \leqslant n$, there is $j, 1 \leqslant j \leqslant n$, for which the number $a_{i}+a_{i+1}+$ $\cdots+a_{i+j-1}$ is divisible by $n$. Notice that, in any such case, we should have $1 \leqslant j \leqslant n-1$, since $a_{1}+a_{2}+\cdots+a_{n}$ is not divisible by $n$. So we may construct recursively a finite sequence of integers $0=i_{0}<i_{1}<i_{2}<\cdots<i_{n}$ with $i_{s+1}-i_{s} \leqslant n-1$ for $0 \leqslant s \leqslant n-1$ such that, for $0 \leqslant s \leqslant n-1$,  $$ a_{i_{s}+1}+a_{i_{s}+2}+\cdots+a_{i_{s+1}} \equiv 0 \quad(\bmod n) $$  (where we take indices modulo $n$ ). Indeed, for $0 \leqslant s<n$, we apply the previous observation to $i=i_{s}+1$ in order to define $i_{s+1}=i_{s}+j$.  In the sequence of $n+1$ indices $i_{0}, i_{1}, i_{2}, \ldots, i_{n}$, by the pigeonhole principle, we have two distinct elements which are congruent modulo $n$. So there are indices $r, s$ with $0 \leqslant r<s \leqslant n$ such that $i_{s} \equiv i_{r}(\bmod n)$ and  $$ a_{i_{r}+1}+a_{i_{r}+2}+\cdots+a_{i_{s}}=\sum_{j=r}^{s-1}\left(a_{i_{j}+1}+a_{i_{j}+2}+\cdots+a_{i_{j+1}}\right) \equiv 0 \quad(\bmod n) $$  Since $i_{s} \equiv i_{r}(\bmod n)$, we have $i_{s}-i_{r}=k \cdot n$ for some positive integer $k$, and, since $i_{j+1}-i_{j} \leqslant$ $n-1$ for $0 \leqslant j \leqslant n-1$, we have $i_{s}-i_{r} \leqslant(n-1) \cdot n$, so $k \leqslant n-1$. But in this case  $$ a_{i_{r}+1}+a_{i_{r}+2}+\cdots+a_{i_{s}}=k \cdot\left(a_{1}+a_{2}+\cdots+a_{n}\right) $$  cannot be a multiple of $n$, since $n$ is prime and neither $k$ nor $a_{1}+a_{2}+\cdots+a_{n}$ is a multiple of $n$. A contradiction.


Call a rational number short if it has finitely many digits in its decimal expansion. For a positive integer $m$, we say that a positive integer $t$ is $m$-tastic if there exists a number $c \in\{1,2,3, \ldots, 2017\}$ such that $\frac{10^{t}-1}{c \cdot m}$ is short, and such that $\frac{10^{k}-1}{c \cdot m}$ is not short for any $1 \leqslant k<t$. Let $S(m)$ be the set of $m$-tastic numbers. Consider $S(m)$ for $m=1,2, \ldots$. What is the maximum number of elements in $S(m)$ ? (Turkey) Answer: 807.

Solution: First notice that $x \in \mathbb{Q}$ is short if and only if there are exponents $a, b \geqslant 0$ such that $2^{a} \cdot 5^{b} \cdot x \in \mathbb{Z}$. In fact, if $x$ is short, then $x=\frac{n}{10^{k}}$ for some $k$ and we can take $a=b=k$; on the other hand, if $2^{a} \cdot 5^{b} \cdot x=q \in \mathbb{Z}$ then $x=\frac{2^{b} \cdot 5^{a} q}{10^{a+b}}$, so $x$ is short.  If $m=2^{a} \cdot 5^{b} \cdot s$, with $\operatorname{gcd}(s, 10)=1$, then $\frac{10^{t}-1}{m}$ is short if and only if $s$ divides $10^{t}-1$. So we may (and will) suppose without loss of generality that $\operatorname{gcd}(m, 10)=1$. Define  $$ C=\{1 \leqslant c \leqslant 2017: \operatorname{gcd}(c, 10)=1\} . $$  The $m$-tastic numbers are then precisely the smallest exponents $t>0$ such that $10^{t} \equiv 1$ $(\bmod \mathrm{cm})$ for some integer $c \in C$, that is, the set of orders of 10 modulo cm . In other words,  $$ S(m)=\left\{\operatorname{ord}_{c m}(10): c \in C\right\} $$  Since there are $4 \cdot 201+3=807$ numbers $c$ with $1 \leqslant c \leqslant 2017$ and $\operatorname{gcd}(c, 10)=1$, namely those such that $c \equiv 1,3,7,9(\bmod 10)$,  $$ |S(m)| \leqslant|C|=807 $$  Now we find $m$ such that $|S(m)|=807$. Let  $$ P=\{1<p \leqslant 2017: p \text { is prime, } p \neq 2,5\} $$  and choose a positive integer $\alpha$ such that every $p \in P$ divides $10^{\alpha}-1$ (e.g. $\alpha=\varphi(T), T$ being the product of all primes in $P$ ), and let $m=10^{\alpha}-1$. Claim. For every $c \in C$, we have  $$ \operatorname{ord}_{c m}(10)=c \alpha $$  As an immediate consequence, this implies $|S(m)|=|C|=807$, finishing the problem. Proof. Obviously $\operatorname{ord}_{m}(10)=\alpha$. Let $t=\operatorname{ord}_{c m}(10)$. Then  $$ c m\left|10^{t}-1 \quad \Longrightarrow \quad m\right| 10^{t}-1 \quad \Longrightarrow \quad \alpha \mid t $$  Hence $t=k \alpha$ for some $k \in \mathbb{Z}_{>0}$. We will show that $k=c$. Denote by $\nu_{p}(n)$ the number of prime factors $p$ in $n$, that is, the maximum exponent $\beta$ for which $p^{\beta} \mid n$. For every $\ell \geqslant 1$ and $p \in P$, the Lifting the Exponent Lemma provides  $$ \nu_{p}\left(10^{\ell \alpha}-1\right)=\nu_{p}\left(\left(10^{\alpha}\right)^{\ell}-1\right)=\nu_{p}\left(10^{\alpha}-1\right)+\nu_{p}(\ell)=\nu_{p}(m)+\nu_{p}(\ell) $$  so  $$ \begin{aligned} c m \mid 10^{k \alpha}-1 & \Longleftrightarrow \forall p \in P ; \nu_{p}(c m) \leqslant \nu_{p}\left(10^{k \alpha}-1\right) \\ & \Longleftrightarrow \forall p \in P ; \nu_{p}(m)+\nu_{p}(c) \leqslant \nu_{p}(m)+\nu_{p}(k) \\ & \Longleftrightarrow \forall p \in P ; \nu_{p}(c) \leqslant \nu_{p}(k) \\ & \Longleftrightarrow c \mid k . \end{aligned} $$  The first such $k$ is $k=c$, so $\operatorname{ord}_{c m}(10)=c \alpha$.  Comment. The Lifting the Exponent Lemma states that, for any odd prime $p$, any integers $a, b$ coprime with $p$ such that $p \mid a-b$, and any positive integer exponent $n$,  $$ \nu_{p}\left(a^{n}-b^{n}\right)=\nu_{p}(a-b)+\nu_{p}(n), $$  and, for $p=2$,  $$ \nu_{2}\left(a^{n}-b^{n}\right)=\nu_{2}\left(a^{2}-b^{2}\right)+\nu_{p}(n)-1 . $$  Both claims can be proved by induction on $n$.


Find all pairs $(p, q)$ of prime numbers with $p>q$ for which the number  $$ \frac{(p+q)^{p+q}(p-q)^{p-q}-1}{(p+q)^{p-q}(p-q)^{p+q}-1} $$  is an integer. (Japan) Answer: The only such pair is $(3,2)$.

Solution: Let $M=(p+q)^{p-q}(p-q)^{p+q}-1$, which is relatively prime with both $p+q$ and $p-q$. Denote by $(p-q)^{-1}$ the multiplicative inverse of $(p-q)$ modulo $M$.  By eliminating the term -1 in the numerator,  $$ \begin{aligned} (p+q)^{p+q}(p-q)^{p-q}-1 & \equiv(p+q)^{p-q}(p-q)^{p+q}-1 \quad(\bmod M) \\ (p+q)^{2 q} & \equiv(p-q)^{2 q} \quad(\bmod M) \\ \left((p+q) \cdot(p-q)^{-1}\right)^{2 q} & \equiv 1 \quad(\bmod M) \end{aligned} $$  Case 1: $q \geqslant 5$. Consider an arbitrary prime divisor $r$ of $M$. Notice that $M$ is odd, so $r \geqslant 3$. By (2), the multiplicative order of $\left((p+q) \cdot(p-q)^{-1}\right)$ modulo $r$ is a divisor of the exponent $2 q$ in (2), so it can be $1,2, q$ or $2 q$.  By Fermat's theorem, the order divides $r-1$. So, if the order is $q$ or $2 q$ then $r \equiv 1(\bmod q)$. If the order is 1 or 2 then $r \mid(p+q)^{2}-(p-q)^{2}=4 p q$, so $r=p$ or $r=q$. The case $r=p$ is not possible, because, by applying Fermat's theorem, $M=(p+q)^{p-q}(p-q)^{p+q}-1 \equiv q^{p-q}(-q)^{p+q}-1=\left(q^{2}\right)^{p}-1 \equiv q^{2}-1=(q+1)(q-1) \quad(\bmod p)$ and the last factors $q-1$ and $q+1$ are less than $p$ and thus $p \nmid M$. Hence, all prime divisors of $M$ are either $q$ or of the form $k q+1$; it follows that all positive divisors of $M$ are congruent to 0 or 1 modulo $q$.  Now notice that  $$ M=\left((p+q)^{\frac{p-q}{2}}(p-q)^{\frac{p+q}{2}}-1\right)\left((p+q)^{\frac{p-q}{2}}(p-q)^{\frac{p+q}{2}}+1\right) $$  is the product of two consecutive positive odd numbers; both should be congruent to 0 or 1 modulo $q$. But this is impossible by the assumption $q \geqslant 5$. So, there is no solution in Case 1 . Case 2: $q=2$. By (1), we have $M \mid(p+q)^{2 q}-(p-q)^{2 q}=(p+2)^{4}-(p-2)^{4}$, so  $$ \begin{gathered} (p+2)^{p-2}(p-2)^{p+2}-1=M \leqslant(p+2)^{4}-(p-2)^{4} \leqslant(p+2)^{4}-1, \\ (p+2)^{p-6}(p-2)^{p+2} \leqslant 1 . \end{gathered} $$  If $p \geqslant 7$ then the left-hand side is obviously greater than 1 . For $p=5$ we have $(p+2)^{p-6}(p-2)^{p+2}=7^{-1} \cdot 3^{7}$ which is also too large.  There remains only one candidate, $p=3$, which provides a solution:  $$ \frac{(p+q)^{p+q}(p-q)^{p-q}-1}{(p+q)^{p-q}(p-q)^{p+q}-1}=\frac{5^{5} \cdot 1^{1}-1}{5^{1} \cdot 1^{5}-1}=\frac{3124}{4}=781 . $$  So in Case 2 the only solution is $(p, q)=(3,2)$.  Case 3: $q=3$. Similarly to Case 2, we have  $$ M \left\lvert\,(p+q)^{2 q}-(p-q)^{2 q}=64 \cdot\left(\left(\frac{p+3}{2}\right)^{6}-\left(\frac{p-3}{2}\right)^{6}\right)\right. $$  Since $M$ is odd, we conclude that  $$ M \left\lvert\,\left(\frac{p+3}{2}\right)^{6}-\left(\frac{p-3}{2}\right)^{6}\right. $$  and  $$ \begin{gathered} (p+3)^{p-3}(p-3)^{p+3}-1=M \leqslant\left(\frac{p+3}{2}\right)^{6}-\left(\frac{p-3}{2}\right)^{6} \leqslant\left(\frac{p+3}{2}\right)^{6}-1 \\ 64(p+3)^{p-9}(p-3)^{p+3} \leqslant 1 \end{gathered} $$  If $p \geqslant 11$ then the left-hand side is obviously greater than 1 . If $p=7$ then the left-hand side is $64 \cdot 10^{-2} \cdot 4^{10}>1$. If $p=5$ then the left-hand side is $64 \cdot 8^{-4} \cdot 2^{8}=2^{2}>1$. Therefore, there is no solution in Case 3.


Find the smallest positive integer $n$, or show that no such $n$ exists, with the following property: there are infinitely many distinct $n$-tuples of positive rational numbers $\left(a_{1}, a_{2}, \ldots, a_{n}\right)$ such that both  $$ a_{1}+a_{2}+\cdots+a_{n} \quad \text { and } \quad \frac{1}{a_{1}}+\frac{1}{a_{2}}+\cdots+\frac{1}{a_{n}} $$  are integers. (Singapore) Answer: $n=3$.

Solution: For $n=1, a_{1} \in \mathbb{Z}_{>0}$ and $\frac{1}{a_{1}} \in \mathbb{Z}_{>0}$ if and only if $a_{1}=1$. Next we show that (i) There are finitely many $(x, y) \in \mathbb{Q}_{>0}^{2}$ satisfying $x+y \in \mathbb{Z}$ and $\frac{1}{x}+\frac{1}{y} \in \mathbb{Z}$  Write $x=\frac{a}{b}$ and $y=\frac{c}{d}$ with $a, b, c, d \in \mathbb{Z}_{>0}$ and $\operatorname{gcd}(a, b)=\operatorname{gcd}(c, d)=1$. Then $x+y \in \mathbb{Z}$ and $\frac{1}{x}+\frac{1}{y} \in \mathbb{Z}$ is equivalent to the two divisibility conditions  $$ b d \mid a d+b c \quad(1) \quad \text { and } \quad a c \mid a d+b c $$  Condition (1) implies that $d|a d+b c \Longleftrightarrow d| b c \Longleftrightarrow d \mid b$ since $\operatorname{gcd}(c, d)=1$. Still from (1) we get $b|a d+b c \Longleftrightarrow b| a d \Longleftrightarrow b \mid d$ since $\operatorname{gcd}(a, b)=1$. From $b \mid d$ and $d \mid b$ we have $b=d$. An analogous reasoning with condition (2) shows that $a=c$. Hence $x=\frac{a}{b}=\frac{c}{d}=y$, i.e., the problem amounts to finding all $x \in \mathbb{Q}_{>0}$ such that $2 x \in \mathbb{Z}_{>0}$ and $\frac{2}{x} \in \mathbb{Z}_{>0}$. Letting $n=2 x \in \mathbb{Z}_{>0}$, we have that $\frac{2}{x} \in \mathbb{Z}_{>0} \Longleftrightarrow \frac{4}{n} \in \mathbb{Z}_{>0} \Longleftrightarrow n=1,2$ or 4 , and there are finitely many solutions, namely $(x, y)=\left(\frac{1}{2}, \frac{1}{2}\right),(1,1)$ or $(2,2)$. (ii) There are infinitely many triples $(x, y, z) \in \mathbb{Q}_{>0}^{2}$ such that $x+y+z \in \mathbb{Z}$ and $\frac{1}{x}+\frac{1}{y}+\frac{1}{z} \in \mathbb{Z}$. We will look for triples such that $x+y+z=1$, so we may write them in the form  $$ (x, y, z)=\left(\frac{a}{a+b+c}, \frac{b}{a+b+c}, \frac{c}{a+b+c}\right) \quad \text { with } a, b, c \in \mathbb{Z}_{>0} $$  We want these to satisfy  $$ \frac{1}{x}+\frac{1}{y}+\frac{1}{z}=\frac{a+b+c}{a}+\frac{a+b+c}{b}+\frac{a+b+c}{c} \in \mathbb{Z} \Longleftrightarrow \frac{b+c}{a}+\frac{a+c}{b}+\frac{a+b}{c} \in \mathbb{Z} $$  Fixing $a=1$, it suffices to find infinitely many pairs $(b, c) \in \mathbb{Z}_{>0}^{2}$ such that  $$ \frac{1}{b}+\frac{1}{c}+\frac{c}{b}+\frac{b}{c}=3 \Longleftrightarrow b^{2}+c^{2}-3 b c+b+c=0 $$  To show that equation (*) has infinitely many solutions, we use Vieta jumping (also known as root flipping): starting with $b=2, c=3$, the following algorithm generates infinitely many solutions. Let $c \geqslant b$, and view (*) as a quadratic equation in $b$ for $c$ fixed:  $$ b^{2}-(3 c-1) \cdot b+\left(c^{2}+c\right)=0 $$  Then there exists another root $b_{0} \in \mathbb{Z}$ of ( $\left.* *\right)$ which satisfies $b+b_{0}=3 c-1$ and $b \cdot b_{0}=c^{2}+c$. Since $c \geqslant b$ by assumption,  $$ b_{0}=\frac{c^{2}+c}{b} \geqslant \frac{c^{2}+c}{c}>c $$  Hence from the solution $(b, c)$ we obtain another one $\left(c, b_{0}\right)$ with $b_{0}>c$, and we can then "jump" again, this time with $c$ as the "variable" in the quadratic (*). This algorithm will generate an infinite sequence of distinct solutions, whose first terms are $(2,3),(3,6),(6,14),(14,35),(35,90),(90,234),(234,611),(611,1598),(1598,4182), \ldots$  Comment. Although not needed for solving this problem, we may also explicitly solve the recursion given by the Vieta jumping. Define the sequence $\left(x_{n}\right)$ as follows:  $$ x_{0}=2, \quad x_{1}=3 \quad \text { and } \quad x_{n+2}=3 x_{n+1}-x_{n}-1 \text { for } n \geqslant 0 $$  Then the triple  $$ (x, y, z)=\left(\frac{1}{1+x_{n}+x_{n+1}}, \frac{x_{n}}{1+x_{n}+x_{n+1}}, \frac{x_{n+1}}{1+x_{n}+x_{n+1}}\right) $$  satisfies the problem conditions for all $n \in \mathbb{N}$. It is easy to show that $x_{n}=F_{2 n+1}+1$, where $F_{n}$ denotes the $n$-th term of the Fibonacci sequence ( $F_{0}=0, F_{1}=1$, and $F_{n+2}=F_{n+1}+F_{n}$ for $n \geqslant 0$ ).


Solution: Call the $n$-tuples $\left(a_{1}, a_{2}, \ldots, a_{n}\right) \in \mathbb{Q}_{>0}^{n}$ satisfying the conditions of the problem statement good, and those for which  $$ f\left(a_{1}, \ldots, a_{n}\right) \stackrel{\text { def }}{=}\left(a_{1}+a_{2}+\cdots+a_{n}\right)\left(\frac{1}{a_{1}}+\frac{1}{a_{2}}+\cdots+\frac{1}{a_{n}}\right) $$  is an integer pretty. Then good $n$-tuples are pretty, and if $\left(b_{1}, \ldots, b_{n}\right)$ is pretty then  $$ \left(\frac{b_{1}}{b_{1}+b_{2}+\cdots+b_{n}}, \frac{b_{2}}{b_{1}+b_{2}+\cdots+b_{n}}, \ldots, \frac{b_{n}}{b_{1}+b_{2}+\cdots+b_{n}}\right) $$  is good since the sum of its components is 1 , and the sum of the reciprocals of its components equals $f\left(b_{1}, \ldots, b_{n}\right)$. We declare pretty $n$-tuples proportional to each other equivalent since they are precisely those which give rise to the same good $n$-tuple. Clearly, each such equivalence class contains exactly one $n$-tuple of positive integers having no common prime divisors. Call such $n$-tuple a primitive pretty tuple. Our task is to find infinitely many primitive pretty $n$-tuples.  For $n=1$, there is clearly a single primitive 1 -tuple. For $n=2$, we have $f(a, b)=\frac{(a+b)^{2}}{a b}$, which can be integral (for coprime $a, b \in \mathbb{Z}_{>0}$ ) only if $a=b=1$ (see for instance (i) in the first solution).  Now we construct infinitely many primitive pretty triples for $n=3$. Fix $b, c, k \in \mathbb{Z}_{>0}$; we will try to find sufficient conditions for the existence of an $a \in \mathbb{Q}_{>0}$ such that $f(a, b, c)=k$. Write $\sigma=b+c, \tau=b c$. From $f(a, b, c)=k$, we have that $a$ should satisfy the quadratic equation  $$ a^{2} \cdot \sigma+a \cdot\left(\sigma^{2}-(k-1) \tau\right)+\sigma \tau=0 $$  whose discriminant is  $$ \Delta=\left(\sigma^{2}-(k-1) \tau\right)^{2}-4 \sigma^{2} \tau=\left((k+1) \tau-\sigma^{2}\right)^{2}-4 k \tau^{2} $$  We need it to be a square of an integer, say, $\Delta=M^{2}$ for some $M \in \mathbb{Z}$, i.e., we want  $$ \left((k+1) \tau-\sigma^{2}\right)^{2}-M^{2}=2 k \cdot 2 \tau^{2} $$  so that it suffices to set  $$ (k+1) \tau-\sigma^{2}=\tau^{2}+k, \quad M=\tau^{2}-k . $$  The first relation reads $\sigma^{2}=(\tau-1)(k-\tau)$, so if $b$ and $c$ satisfy  $$ \tau-1 \mid \sigma^{2} \quad \text { i.e. } \quad b c-1 \mid(b+c)^{2} $$  then $k=\frac{\sigma^{2}}{\tau-1}+\tau$ will be integral, and we find rational solutions to (1), namely  $$ a=\frac{\sigma}{\tau-1}=\frac{b+c}{b c-1} \quad \text { or } \quad a=\frac{\tau^{2}-\tau}{\sigma}=\frac{b c \cdot(b c-1)}{b+c} $$  We can now find infinitely many pairs ( $b, c$ ) satisfying (2) by Vieta jumping. For example, if we impose  $$ (b+c)^{2}=5 \cdot(b c-1) $$  then all pairs $(b, c)=\left(v_{i}, v_{i+1}\right)$ satisfy the above condition, where  $$ v_{1}=2, v_{2}=3, \quad v_{i+2}=3 v_{i+1}-v_{i} \quad \text { for } i \geqslant 0 $$  For $(b, c)=\left(v_{i}, v_{i+1}\right)$, one of the solutions to (1) will be $a=(b+c) /(b c-1)=5 /(b+c)=$ $5 /\left(v_{i}+v_{i+1}\right)$. Then the pretty triple $(a, b, c)$ will be equivalent to the integral pretty triple  $$ \left(5, v_{i}\left(v_{i}+v_{i+1}\right), v_{i+1}\left(v_{i}+v_{i+1}\right)\right) $$  After possibly dividing by 5 , we obtain infinitely many primitive pretty triples, as required. Comment. There are many other infinite series of $(b, c)=\left(v_{i}, v_{i+1}\right)$ with $b c-1 \mid(b+c)^{2}$. Some of them are:  $$ \begin{array}{llll} v_{1}=1, & v_{2}=3, & v_{i+1}=6 v_{i}-v_{i-1}, & \left(v_{i}+v_{i+1}\right)^{2}=8 \cdot\left(v_{i} v_{i+1}-1\right) ; \\ v_{1}=1, & v_{2}=2, & v_{i+1}=7 v_{i}-v_{i-1}, & \left(v_{i}+v_{i+1}\right)^{2}=9 \cdot\left(v_{i} v_{i+1}-1\right) ; \\ v_{1}=1, & v_{2}=5, & v_{i+1}=7 v_{i}-v_{i-1}, & \left(v_{i}+v_{i+1}\right)^{2}=9 \cdot\left(v_{i} v_{i+1}-1\right) \end{array} $$  (the last two are in fact one sequence prolonged in two possible directions).


Let $p$ be an odd prime number and $\mathbb{Z}_{>0}$ be the set of positive integers. Suppose that a function $f: \mathbb{Z}_{>0} \times \mathbb{Z}_{>0} \rightarrow\{0,1\}$ satisfies the following properties:  - $f(1,1)=0$; - $f(a, b)+f(b, a)=1$ for any pair of relatively prime positive integers $(a, b)$ not both equal to 1 ; - $f(a+b, b)=f(a, b)$ for any pair of relatively prime positive integers $(a, b)$.  Prove that  $$ \sum_{n=1}^{p-1} f\left(n^{2}, p\right) \geqslant \sqrt{2 p}-2 $$  (Italy)

Solution: Denote by $\mathbb{A}$ the set of all pairs of coprime positive integers. Notice that for every $(a, b) \in \mathbb{A}$ there exists a pair $(u, v) \in \mathbb{Z}^{2}$ with $u a+v b=1$. Moreover, if $\left(u_{0}, v_{0}\right)$ is one such pair, then all such pairs are of the form $(u, v)=\left(u_{0}+k b, v_{0}-k a\right)$, where $k \in \mathbb{Z}$. So there exists a unique such pair $(u, v)$ with $-b / 2<u \leqslant b / 2$; we denote this pair by $(u, v)=g(a, b)$. Lemma. Let $(a, b) \in \mathbb{A}$ and $(u, v)=g(a, b)$. Then $f(a, b)=1 \Longleftrightarrow u>0$. Proof. We induct on $a+b$. The base case is $a+b=2$. In this case, we have that $a=b=1$, $g(a, b)=g(1,1)=(0,1)$ and $f(1,1)=0$, so the claim holds.  Assume now that $a+b>2$, and so $a \neq b$, since $a$ and $b$ are coprime. Two cases are possible. Case 1: $a>b$.  Notice that $g(a-b, b)=(u, v+u)$, since $u(a-b)+(v+u) b=1$ and $u \in(-b / 2, b / 2]$. Thus $f(a, b)=1 \Longleftrightarrow f(a-b, b)=1 \Longleftrightarrow u>0$ by the induction hypothesis. Case 2: $a<b$. (Then, clearly, $b \geqslant 2$.) Now we estimate $v$. Since $v b=1-u a$, we have  $$ 1+\frac{a b}{2}>v b \geqslant 1-\frac{a b}{2}, \quad \text { so } \quad \frac{1+a}{2} \geqslant \frac{1}{b}+\frac{a}{2}>v \geqslant \frac{1}{b}-\frac{a}{2}>-\frac{a}{2} . $$  Thus $1+a>2 v>-a$, so $a \geqslant 2 v>-a$, hence $a / 2 \geqslant v>-a / 2$, and thus $g(b, a)=(v, u)$. Observe that $f(a, b)=1 \Longleftrightarrow f(b, a)=0 \Longleftrightarrow f(b-a, a)=0$. We know from Case 1 that $g(b-a, a)=(v, u+v)$. We have $f(b-a, a)=0 \Longleftrightarrow v \leqslant 0$ by the inductive hypothesis. Then, since $b>a \geqslant 1$ and $u a+v b=1$, we have $v \leqslant 0 \Longleftrightarrow u>0$, and we are done.  The Lemma proves that, for all $(a, b) \in \mathbb{A}, f(a, b)=1$ if and only if the inverse of $a$ modulo $b$, taken in $\{1,2, \ldots, b-1\}$, is at most $b / 2$. Then, for any odd prime $p$ and integer $n$ such that $n \not \equiv 0(\bmod p), f\left(n^{2}, p\right)=1$ iff the inverse of $n^{2} \bmod p$ is less than $p / 2$. Since $\left\{n^{2} \bmod p: 1 \leqslant n \leqslant p-1\right\}=\left\{n^{-2} \bmod p: 1 \leqslant n \leqslant p-1\right\}$, including multiplicities (two for each quadratic residue in each set), we conclude that the desired sum is twice the number of quadratic residues that are less than $p / 2$, i.e.,  $$ \left.\sum_{n=1}^{p-1} f\left(n^{2}, p\right)=2 \left\lvert\,\left\{k: 1 \leqslant k \leqslant \frac{p-1}{2} \text { and } k^{2} \bmod p<\frac{p}{2}\right\}\right. \right\rvert\, . $$  Since the number of perfect squares in the interval $[1, p / 2)$ is $\lfloor\sqrt{p / 2}\rfloor>\sqrt{p / 2}-1$, we conclude that  $$ \sum_{n=1}^{p-1} f\left(n^{2}, p\right)>2\left(\sqrt{\frac{p}{2}}-1\right)=\sqrt{2 p}-2 $$


Solution: We provide a different proof for the Lemma. For this purpose, we use continued fractions to find $g(a, b)=(u, v)$ explicitly.  The function $f$ is completely determined on $\mathbb{A}$ by the following Claim. Represent $a / b$ as a continued fraction; that is, let $a_{0}$ be an integer and $a_{1}, \ldots, a_{k}$ be positive integers such that $a_{k} \geqslant 2$ and  $$ \frac{a}{b}=a_{0}+\frac{1}{a_{1}+\frac{1}{a_{2}+\frac{1}{\cdots+\frac{1}{a_{k}}}}}=\left[a_{0} ; a_{1}, a_{2}, \ldots, a_{k}\right] . $$  Then $f(a, b)=0 \Longleftrightarrow k$ is even. Proof. We induct on $b$. If $b=1$, then $a / b=[a]$ and $k=0$. Then, for $a \geqslant 1$, an easy induction shows that $f(a, 1)=f(1,1)=0$.  Now consider the case $b>1$. Perform the Euclidean division $a=q b+r$, with $0 \leqslant r<b$. We have $r \neq 0$ because $\operatorname{gcd}(a, b)=1$. Hence  $$ f(a, b)=f(r, b)=1-f(b, r), \quad \frac{a}{b}=\left[q ; a_{1}, \ldots, a_{k}\right], \quad \text { and } \quad \frac{b}{r}=\left[a_{1} ; a_{2}, \ldots, a_{k}\right] . $$  Then the number of terms in the continued fraction representations of $a / b$ and $b / r$ differ by one. Since $r<b$, the inductive hypothesis yields  $$ f(b, r)=0 \Longleftrightarrow k-1 \text { is even, } $$  and thus  $$ f(a, b)=0 \Longleftrightarrow f(b, r)=1 \Longleftrightarrow k-1 \text { is odd } \Longleftrightarrow k \text { is even. } $$  Now we use the following well-known properties of continued fractions to prove the Lemma: Let $p_{i}$ and $q_{i}$ be coprime positive integers with $\left[a_{0} ; a_{1}, a_{2}, \ldots, a_{i}\right]=p_{i} / q_{i}$, with the notation borrowed from the Claim. In particular, $a / b=\left[a_{0} ; a_{1}, a_{2}, \ldots, a_{k}\right]=p_{k} / q_{k}$. Assume that $k>0$ and define $q_{-1}=0$ if necessary. Then  - $q_{k}=a_{k} q_{k-1}+q_{k-2}, \quad$ and - $a q_{k-1}-b p_{k-1}=p_{k} q_{k-1}-q_{k} p_{k-1}=(-1)^{k-1}$.  Assume that $k>0$. Then $a_{k} \geqslant 2$, and  $$ b=q_{k}=a_{k} q_{k-1}+q_{k-2} \geqslant a_{k} q_{k-1} \geqslant 2 q_{k-1} \Longrightarrow q_{k-1} \leqslant \frac{b}{2} $$  with strict inequality for $k>1$, and  $$ (-1)^{k-1} q_{k-1} a+(-1)^{k} p_{k-1} b=1 $$  Now we finish the proof of the Lemma. It is immediate for $k=0$. If $k=1$, then $(-1)^{k-1}=1$, so  $$ -b / 2<0 \leqslant(-1)^{k-1} q_{k-1} \leqslant b / 2 $$  If $k>1$, we have $q_{k-1}<b / 2$, so  $$ -b / 2<(-1)^{k-1} q_{k-1}<b / 2 $$  Thus, for any $k>0$, we find that $g(a, b)=\left((-1)^{k-1} q_{k-1},(-1)^{k} p_{k-1}\right)$, and so  $$ f(a, b)=1 \Longleftrightarrow k \text { is odd } \Longleftrightarrow u=(-1)^{k-1} q_{k-1}>0 $$  Comment 1. The Lemma can also be established by observing that $f$ is uniquely defined on $\mathbb{A}$, defining $f_{1}(a, b)=1$ if $u>0$ in $g(a, b)=(u, v)$ and $f_{1}(a, b)=0$ otherwise, and verifying that $f_{1}$ satisfies all the conditions from the statement.  It seems that the main difficulty of the problem is in conjecturing the Lemma. Comment 2. The case $p \equiv 1(\bmod 4)$ is, in fact, easier than the original problem. We have, in general, for $1 \leqslant a \leqslant p-1$, $f(a, p)=1-f(p, a)=1-f(p-a, a)=f(a, p-a)=f(a+(p-a), p-a)=f(p, p-a)=1-f(p-a, p)$. If $p \equiv 1(\bmod 4)$, then $a$ is a quadratic residue modulo $p$ if and only if $p-a$ is a quadratic residue modulo $p$. Therefore, denoting by $r_{k}$ (with $1 \leqslant r_{k} \leqslant p-1$ ) the remainder of the division of $k^{2}$ by $p$, we get  $$ \sum_{n=1}^{p-1} f\left(n^{2}, p\right)=\sum_{n=1}^{p-1} f\left(r_{n}, p\right)=\frac{1}{2} \sum_{n=1}^{p-1}\left(f\left(r_{n}, p\right)+f\left(p-r_{n}, p\right)\right)=\frac{p-1}{2} $$  Comment 3. The estimate for the sum $\sum_{n=1}^{p} f\left(n^{2}, p\right)$ can be improved by refining the final argument in Solution 1. In fact, one can prove that  $$ \sum_{n=1}^{p-1} f\left(n^{2}, p\right) \geqslant \frac{p-1}{16} $$  By counting the number of perfect squares in the intervals $[k p,(k+1 / 2) p)$, we find that  $$ \sum_{n=1}^{p-1} f\left(n^{2}, p\right)=\sum_{k=0}^{p-1}\left(\left\lfloor\sqrt{\left(k+\frac{1}{2}\right) p}\right\rfloor-\lfloor\sqrt{k p}\rfloor\right) . $$  Each summand of (2) is non-negative. We now estimate the number of positive summands. Suppose that a summand is zero, i.e.,  $$ \left\lfloor\sqrt{\left(k+\frac{1}{2}\right) p}\right\rfloor=\lfloor\sqrt{k p}\rfloor=: q . $$  Then both of the numbers $k p$ and $k p+p / 2$ lie within the interval $\left[q^{2},(q+1)^{2}\right)$. Hence  $$ \frac{p}{2}<(q+1)^{2}-q^{2} $$  which implies  $$ q \geqslant \frac{p-1}{4} $$  Since $q \leqslant \sqrt{k p}$, if the $k^{\text {th }}$ summand of (2) is zero, then  $$ k \geqslant \frac{q^{2}}{p} \geqslant \frac{(p-1)^{2}}{16 p}>\frac{p-2}{16} \Longrightarrow k \geqslant \frac{p-1}{16} $$  So at least the first $\left\lceil\frac{p-1}{16}\right\rceil$ summands (from $k=0$ to $k=\left\lceil\frac{p-1}{16}\right\rceil-1$ ) are positive, and the result follows.  Comment 4. The bound can be further improved by using different methods. In fact, we prove that  $$ \sum_{n=1}^{p-1} f\left(n^{2}, p\right) \geqslant \frac{p-3}{4} $$  To that end, we use the Legendre symbol  $$ \left(\frac{a}{p}\right)= \begin{cases}0 & \text { if } p \mid a \\ 1 & \text { if } a \text { is a nonzero quadratic residue } \bmod p \\ -1 & \text { otherwise. }\end{cases} $$  We start with the following Claim, which tells us that there are not too many consecutive quadratic residues or consecutive quadratic non-residues.  Claim. $\sum_{n=1}^{p-1}\left(\frac{n}{p}\right)\left(\frac{n+1}{p}\right)=-1$. Proof. We have $\left(\frac{n}{p}\right)\left(\frac{n+1}{p}\right)=\left(\frac{n(n+1)}{p}\right)$. For $1 \leqslant n \leqslant p-1$, we get that $n(n+1) \equiv n^{2}\left(1+n^{-1}\right)(\bmod p)$, hence $\left(\frac{n(n+1)}{p}\right)=\left(\frac{1+n^{-1}}{p}\right)$. Since $\left\{1+n^{-1} \bmod p: 1 \leqslant n \leqslant p-1\right\}=\{0,2,3, \ldots, p-1 \bmod p\}$, we find  $$ \sum_{n=1}^{p-1}\left(\frac{n}{p}\right)\left(\frac{n+1}{p}\right)=\sum_{n=1}^{p-1}\left(\frac{1+n^{-1}}{p}\right)=\sum_{n=1}^{p-1}\left(\frac{n}{p}\right)-1=-1 $$  because $\sum_{n=1}^{p}\left(\frac{n}{p}\right)=0$. Observe that (1) becomes  $$ \sum_{n=1}^{p-1} f\left(n^{2}, p\right)=2|S|, \quad S=\left\{r: 1 \leqslant r \leqslant \frac{p-1}{2} \text { and }\left(\frac{r}{p}\right)=1\right\} $$  We connect $S$ with the sum from the claim by pairing quadratic residues and quadratic non-residues. To that end, define  $$ \begin{aligned} S^{\prime} & =\left\{r: 1 \leqslant r \leqslant \frac{p-1}{2} \text { and }\left(\frac{r}{p}\right)=-1\right\} \\ T & =\left\{r: \frac{p+1}{2} \leqslant r \leqslant p-1 \text { and }\left(\frac{r}{p}\right)=1\right\} \\ T^{\prime} & =\left\{r: \frac{p+1}{2} \leqslant r \leqslant p-1 \text { and }\left(\frac{r}{p}\right)=-1\right\} \end{aligned} $$  Since there are exactly $(p-1) / 2$ nonzero quadratic residues modulo $p,|S|+|T|=(p-1) / 2$. Also we obviously have $|T|+\left|T^{\prime}\right|=(p-1) / 2$. Then $|S|=\left|T^{\prime}\right|$.  For the sake of brevity, define $t=|S|=\left|T^{\prime}\right|$. If $\left(\frac{n}{p}\right)\left(\frac{n+1}{p}\right)=-1$, then exactly of one the numbers $\left(\frac{n}{p}\right)$ and $\left(\frac{n+1}{p}\right)$ is equal to 1 , so  $$ \left\lvert\,\left\{n: 1 \leqslant n \leqslant \frac{p-3}{2} \text { and }\left(\frac{n}{p}\right)\left(\frac{n+1}{p}\right)=-1\right\}|\leqslant|S|+|S-1|=2 t\right. $$  On the other hand, if $\left(\frac{n}{p}\right)\left(\frac{n+1}{p}\right)=-1$, then exactly one of $\left(\frac{n}{p}\right)$ and $\left(\frac{n+1}{p}\right)$ is equal to -1 , and  $$ \left\lvert\,\left\{n: \frac{p+1}{2} \leqslant n \leqslant p-2 \text { and }\left(\frac{n}{p}\right)\left(\frac{n+1}{p}\right)=-1\right\}\left|\leqslant\left|T^{\prime}\right|+\left|T^{\prime}-1\right|=2 t .\right.\right. $$  Thus, taking into account that the middle term $\left(\frac{(p-1) / 2}{p}\right)\left(\frac{(p+1) / 2}{p}\right)$ may happen to be -1 ,  $$ \left.\left\lvert\,\left\{n: 1 \leqslant n \leqslant p-2 \text { and }\left(\frac{n}{p}\right)\left(\frac{n+1}{p}\right)=-1\right\}\right. \right\rvert\, \leqslant 4 t+1 $$  This implies that  $$ \left.\left\lvert\,\left\{n: 1 \leqslant n \leqslant p-2 \text { and }\left(\frac{n}{p}\right)\left(\frac{n+1}{p}\right)=1\right\}\right. \right\rvert\, \geqslant(p-2)-(4 t+1)=p-4 t-3 $$  and so  $$ -1=\sum_{n=1}^{p-1}\left(\frac{n}{p}\right)\left(\frac{n+1}{p}\right) \geqslant p-4 t-3-(4 t+1)=p-8 t-4 $$  which implies $8 t \geqslant p-3$, and thus  $$ \sum_{n=1}^{p-1} f\left(n^{2}, p\right)=2 t \geqslant \frac{p-3}{4} $$  Comment 5. It is possible to prove that  $$ \sum_{n=1}^{p-1} f\left(n^{2}, p\right) \geqslant \frac{p-1}{2} $$  The case $p \equiv 1(\bmod 4)$ was already mentioned, and it is the equality case. If $p \equiv 3(\bmod 4)$, then, by a theorem of Dirichlet, we have  $$ \left.\left\lvert\,\left\{r: 1 \leqslant r \leqslant \frac{p-1}{2} \text { and }\left(\frac{r}{p}\right)=1\right\}\right. \right\rvert\,>\frac{p-1}{4} $$  which implies the result. See https://en.wikipedia.org/wiki/Quadratic_residue\#Dirichlet.27s_formulas for the full statement of the theorem. It seems that no elementary proof of it is known; a proof using complex analysis is available, for instance, in Chapter 7 of the book Quadratic Residues and Non-Residues: Selected Topics, by Steve Wright, available in https://arxiv.org/abs/1408.0235. ![](https://cdn.mathpix.com/cropped/2024_11_18_ff08e3c077fa2f8c16b2g-96.jpg?height=138&width=204&top_left_y=2241&top_left_x=315)  BIÊNIO DA MATEMATICA BRASIL ![](https://cdn.mathpix.com/cropped/2024_11_18_ff08e3c077fa2f8c16b2g-96.jpg?height=249&width=683&top_left_y=2251&top_left_x=1052) ![](https://cdn.mathpix.com/cropped/2024_11_18_ff08e3c077fa2f8c16b2g-96.jpg?height=132&width=338&top_left_y=2607&top_left_x=1436)   [^0]:    *The name Dirichlet interval is chosen for the reason that $g$ theoretically might act similarly to the Dirichlet function on this interval.