![](https://cdn.mathpix.com/cropped/2024_06_05_95e557bc4ef4e666f168g-01.jpg?height=420&width=1214&top_left_y=178&top_left_x=428) # Contest Problems with Solutions ## $\mathrm{I}-1$ A Find all surjective functions $f: \mathbb{N} \rightarrow \mathbb{N}$ such that for all positive integers $a$ and $b$, exactly one of the following equations is true: $$ \begin{aligned} f(a) & =f(b) \\ f(a+b) & =\min \{f(a), f(b)\} \end{aligned} $$ Remarks: $\mathbb{N}$ denotes the set of all positive integers. A function $f: X \rightarrow Y$ is said to be surjective if for every $y \in Y$ there exists $x \in X$ such that $f(x)=y$. Solution 1. Each positive integer can be uniquely written as $n=2^{k} l$ where $k \geqslant 0$ and $l$ is odd. We will show that the only function satisfying the conditions is $f\left(2^{k} l\right)=k+1$ for all $k \geqslant 0$ and all odd $l$. Assume that $f(1) \neq 1$. Since $f$ is surjective, there exists $a \in \mathbb{N}$ such that $f(a)=1$. Since $f(1) \neq 1=f(a)$, we get $f(a+1)=\min \{f(a), f(1)\}=1$, and inductively we get $f(n)=1$ for each $n \geqslant a$. However, this contradicts the surjectivity of $f$. Therefore $f(1)=1$. Then $f(2) \neq \min \{f(1), f(1)\}=1$, and $f(3)=\min \{f(1), f(2)\}=1$. Now it easily follows by induction that $f(n)=1$ if $n$ is odd and $f(n)>1$ if $n$ is even. We will show by induction on $k$ that $f\left(2^{k} l\right)=k+1$ for all odd $l$ and $f\left(2^{k} m\right)>k+1$ for all even $m$. The basis of induction has been proved above. Assume that the statement holds for all $k1$ if $n$ is even, as we have shown above. Therefore $f\left(2^{k_{0}} l\right)=k_{0}+1$ for odd $l$ and $f\left(2^{k_{0}} \mathrm{~m}\right)>k_{0}+1$ for even $m$, which completes the induction. It is easy to check that this function indeed satisfies the conditions of the problem. Solution 1a. Like in Solution 1 we prove that $$ f(\text { odd })=1, \quad \text { and } \quad f(\text { even })>1 $$ We will show by induction on $k$ that $f\left(2^{k} l\right)=k+1$ for all odd $l$ and $f\left(2^{k} m\right)>k+1$ for all even $m$. The basis of induction has been proved above. Assume that the statement holds for all $kk_{0}+1$. Surjectivity of $f$ implies, that there exists positive integer $b$ such that $f(b)=k_{0}+1$. By induction hypothesis $b$ is of the form $b=2^{k_{0}} r$ for some $r$ ( $r$ may be odd or even). Considering the pair $\left(2^{k_{0}}, b\right)$ we get $f\left(2^{k_{0}}(r+1)\right)=f\left(b+2^{k_{0}}\right)=\min \left\{f\left(2^{k_{0}}\right), f(b)\right\}=k_{0}+1$. By induction we get $f\left(2^{k_{0}} r^{\prime}\right)=k_{0}+1$ for all $r^{\prime} \geqslant r$, contradicting the surjectivity of $f$. Hence $f\left(2^{k_{0}}\right)=k_{0}+1$. Conditions of the problem and induction hypothesis imply that $f(n)=k_{0}+1$ iff $f\left(n+2^{k_{0}}\right)>k_{0}+1$. Therefore it follows inductively that $f\left(2^{k_{0}} l\right)=k_{0}+1$ for odd $l$ and $f\left(2^{k_{0}} m\right)>k_{0}+1$ for even $m$, which finishes the induction step. It is easy to check that the function defined by $f\left(2^{k_{0}} l\right)=k_{0}+1$ for odd $l$ indeed satisfies the conditions of the problem. Solution 2. Like in Solution 1 we prove that $f($ odd $)=1$, and $f($ even $)>1$. Define a sequence of functions $g_{k}: \mathbb{N} \rightarrow \mathbb{N}$ by $$ g_{0}(n)=f(n) \quad \text { and } \quad g_{k}(n)=g_{k-1}(2 n)-1, \quad \text { for } k \in \mathbb{N} $$ Using first part of solution we prove by induction that all $g_{k}$ satisfy the initial conditions of the problem (they map to $\mathbb{N}$, are surjective and satisfies mutually exclusive equations). It follows from the first part of the solution that $g_{k}($ odd $)=1$ for all $k=0,1,2, \ldots$ From $g_{k}(l)=1$ for odd $l$ we inductively obtain $f\left(2^{k} l\right)=k+i$ by backward substitution. This shows that shows that the problem has a unique solution given by $f\left(2^{k} l\right)=k+1$ for all $k \geqslant 0$ and all odd $l$. It is easy to check that this function indeed satisfies the conditions of the problem. Solution 3. Plugging pair $(a, a)$ into the given equations we obtain $f(2 a) \neq \min \{f(a), f(a)\}=$ $f(a)$, in particular $f(4 a) \neq f(2 a)$. From pair $(a, 2 a)$ we get $f(3 a)=f(2 a+a)=\min \{f(2 a), f(a)\}$. Suppose $f(2 a)f(a)$. Next we prove by induction on $l$ that $f(l a)=f(a)$ for all odd $l$. For $l=1$, there is nothing to show. We assume that $f((l-2) a)=f(a)$. As $f(2 a)>f(a)$, we have $$ f(l a)=\min \{f((l-2) a), f(2 a)\}=\min \{f(a), f(2 a)\}=f(a) $$ which proves the induction step. Let now $n=2^{k} l$ for odd $l$. By the above we have $f(n)=f\left(2^{k}\right)$. Thus we only have to determine $f\left(2^{k}\right)$ for $k \geqslant 0$. Since $f(2 a)>f(a)$ for all $a, f\left(2^{k}\right)$ is increasing in $k$. By surjectivity, the only solution is $f\left(2^{k}\right)=k+1$. It is easily seen that $f\left(2^{k} l\right)=k+1$, is indeed a solution. ## $\mathrm{I}-2 \quad \mathrm{C}$ Let $n \geqslant 3$ be an integer. An inner diagonal of a simple $n$-gon is a diagonal that is contained in the $n$-gon. Denote by $D(P)$ the number of all inner diagonals of a simple $n$-gon $P$ and by $D(n)$ the least possible value of $D(Q)$, where $Q$ is a simple $n$-gon. Prove that no two inner diagonals of $P$ intersect (except possibly at a common endpoint) if and only if $D(P)=D(n)$. Remark: A simple $n$-gon is a non-self-intersecting polygon with $n$ vertices. A polygon is not necessarily convex. Solution 1. First we prove that for every $n$-gon $P$ with $n \geqslant 4$ we have $D(P) \geqslant 1$. Let $A$ be one of the vertices of $P$ with inner angle les than $180^{\circ}$. Denote the two vertices adjacent to $A$ by $B$ and $C$. The segment $B C$ is a diagonal of $P$, since $n \geqslant 4$. If it lies in $P$, we are done, so suppose it does not lie in $P$. Let $C^{\prime}$ be the unique point on the segment $A C$ such that the triangle $A B C^{\prime}$ lies in $P$ and the segment $B C^{\prime}$ contains at least one point in the boundary of $P$ distinct from $B$ and $C^{\prime}$. Let $D \neq C^{\prime}$ be the point on the segment $B C^{\prime}$, which lies in the boundary of $P$ and is closest to $C^{\prime}$. Then $D$ must be a vertex of $P$ and $A D$ is an inner diagonal. Next we prove that $D(n)=n-3$. ![](https://cdn.mathpix.com/cropped/2024_06_05_95e557bc4ef4e666f168g-04.jpg?height=343&width=351&top_left_y=1502&top_left_x=858) On the picture diagonals between pairs of points on bottom are clearly outer because that part of polygon is concave. Therefore inner diagonals only exist between upper point and lower points. Number of those diagonals is $n-3$ therefore $D(n) \leqslant n-3$. We prove by induction that $D(n) \geqslant n-3$. The case $n=3$ is clear. So suppose $n \geqslant 4$ and let $P$ be a $n$-gon. By the above there exists an inner diagonal of $P$. This diagonal divides $P$ into two polygons $R$ and $S$ with $k$ and $m$ vertices respectively. Clearly $k, mn$. Let $m=n+k$ for a positive integer $k$. Without loss of generality, we may assume $a>b$. In that case $$ \frac{a^{m}+b^{m}}{a^{n}+b^{n}}>\frac{a^{n} \cdot b^{k}+b^{m}}{a^{n}+b^{n}}=b^{k} $$ thus there exists a positive integer $t$ such that $$ \frac{a^{m}+b^{m}}{a^{n}+b^{n}}=b^{k}+t $$ This equation can be written as follows: $$ \begin{aligned} a^{m}+b^{m} & =\left(b^{k}+t\right)\left(a^{n}+b^{n}\right), \\ a^{m} & =a^{n} b^{k}+t\left(a^{n}+b^{n}\right) . \end{aligned} $$ Since $a$ and $b$ are relatively prime, $a^{n}+b^{n}$ and $a^{n}$ are relatively prime as well. Therefore, from the last equation we can conclude that $t$ is divisible by $a^{n}$. Let $c$ be a positive integer such that $t=c \cdot a^{n}$. We have $$ a^{k}=b^{k}+c \cdot a^{n}+c \cdot b^{n} $$ The right-hand side of the previous equation is greater than $a^{n}$ so we conclude that $k>n$. Previous equation can be written as $$ a^{n}\left(a^{k-n}-c\right)=b^{n}\left(b^{k-n}+c\right) \text {. } $$ This implies that $b^{k-n}+c$ is divisible by $a^{n}$, since $a$ and $b$ are relatively prime. Let $x$ be a positive integer such that $$ b^{k-n}+c=x \cdot a^{n} $$ The previous equation gives us $$ a^{k-n}-c=x \cdot b^{n} $$ Summing the last two equations gives us $$ a^{k-n}+b^{k-n}=x\left(a^{n}+b^{n}\right) $$ which means that $$ \frac{a^{k-n}+b^{k-n}}{a^{n}+b^{n}} $$ is an integer. Since $(k-n)+n=kn$. Write $m=k n+r$, where $k \geqslant 1$ and $0 \leqslant rx_{j}$. So the sum to the right equals less than $(n-1)+(n-3)+\ldots\left(n-2\left\lfloor\frac{n}{2}\right\rfloor+1\right)$. Times 2 equals ... $\left\lfloor\frac{n^{2}}{2}\right\rfloor$. Solution 3. $\quad S(x)=\sum_{i=1}^{n}\left|x_{i}-i\right|$ When we resolve absolute values, we get $$ S(x)=\sum_{\text {some } \mathrm{i}}\left(x_{i}-i\right)+\sum_{\text {other } \mathrm{i}}\left(i-x_{i}\right) $$ so $$ S(x)=\sum_{i=1}^{n} a_{i}-\sum_{i=1}^{n} b_{i} $$ where the numbers $a_{i}$ and $b_{i}$ are all numbers from 1 to $n$ (twice!). So $$ S(x) \leqslant\left(n+n+(n-1)+(n-1)+\ldots+\left(\left\lfloor\frac{n}{2}\right\rfloor+1\right)\right)-\left(1+1+2+2+\ldots+\left\lfloor\frac{n+1}{2}\right\rfloor\right) $$ which evaluates to ... $\left\lfloor\frac{n^{2}}{2}\right\rfloor$. Equality is attained when $i$ and $x_{i}$ are on different sides of $\frac{n+1}{2}$, for all $i$. ## T-4 C Let $N$ be a positive integer. In each of the $N^{2}$ unit squares of an $N \times N$ board, one of the two diagonals is drawn. The drawn diagonals divide the $N \times N$ board into $K$ regions. For each $N$, determine the smallest and the largest possible values of $K$. ![](https://cdn.mathpix.com/cropped/2024_06_05_95e557bc4ef4e666f168g-17.jpg?height=465&width=462&top_left_y=487&top_left_x=797) Example with $N=3, K=7$ Answer. The smallest $K$ is $2 N$ and the largest is $\left\lfloor\frac{(N+1)^{2}+1}{2}\right\rfloor$. ## Solution 1. Minimum A small triangle is a right-angled isosceles triangle whose area is $\frac{1}{2}$ whose hypotenuse is a diagonal of a unit square. A board segment is a horizontal or a vertical segment on the boundary of the board. There are $4 N$ board segments and each of these segments belongs to the boundary of some region. Crucial remark is that each region has either 0 or 2 board segments on its boundary. Indeed, let $R$ be a region that has at least one board segment on its boundary. Let us colour one such board segment in red and then colour the small triangle whose leg is that board segment. In each subsequent step we colour red the unique small triangle which was not coloured so far and which has one of its legs coloured red. This process ends when the other leg of the small triangle is also a board segment. In this way we have exhausted all small triangles of which $R$ consists and shown that $R$ has exactly two board segments on its boundary. It follows that if the number of regions is $K$, then there is at most $2 K$ board segments. Thus $$ 2 K \geqslant 4 N \quad \Longrightarrow \quad K \geqslant 2 N $$ Example with $K=2 N$ : ## Maximum The sum of areas of all regions is constant as it is equal to the area of the board. ![](https://cdn.mathpix.com/cropped/2024_06_05_95e557bc4ef4e666f168g-18.jpg?height=523&width=514&top_left_y=178&top_left_x=774) An inner region is a region that has no board segments on its boundary. The boundary of an inner region consists of diagonals and all of them lie on one of two parallel directions. Let us start at some point of the boundary of an inner region and trace the boundary clockwise. In order to return to the same point (i.e. to close the boundary) we need to change direction at least three times, which means that there are at least four diagonals on its boundary. Each diagonal belongs to a different small triangle, so the area of an inner region is at least 2 . If a region is not inner, then it has exactly two board segments on its boundary. If these two segments meet at the corner of a board, then the region consists of a single small triangle and has area $\frac{1}{2}$. We call such regions corner regions. If a region is not inner and not a corner region, we call it outer. An outer region has exactly two board segments on its boundary, which are not legs of the same small triangle, so each such region has an area at least 1. The area is exactly 1 if the two board segments on the boundary are on the same side of the board and share an endpoint. The number of non inner regions is $2 N$, so their area is at least $4 \cdot \frac{1}{2}+(2 N-4) \cdot 1=2 N-2$. Case 1. If $N$ is even, it is possible to make 4 corner regions and $4 \cdot\left(\frac{1}{2} N-1\right)=2 N-4$ regions of area 1. So, the area on non inner regions is at least $2 N-2$ and the area of inner regions is thus at most $N^{2}-2 N+2$. It follows that there are at most $\frac{1}{2}\left(N^{2}-2 N+2\right)$ inner regions, i.e. there are at most $$ 2 N+\frac{N^{2}-2 N+2}{2}=\frac{(N+1)^{2}+1}{2} $$ regions when $N$ is even. Case 2. Let us consider the case when $N$ is odd. If there are exactly 2 corner regions, the total are of outer and corner regions is at least $2 \cdot \frac{1}{2}+(2 N-2) \cdot 1=2 N-1$. If there are 3 corner regions, then there are two sides of the board with 2 board segments belonging to corner regions. These sides have an odd number of board segments belonging to outer regions. Hence there must be an outer region which has two board segments on different sides of the boards and its area is at least $\frac{3}{2}$. We see that in this case the area of all outer and corner regions is at least $3 \cdot \frac{1}{2}+\frac{3}{2}+(2 N-4) \cdot 1=2 N-1$. Also, if there are 4 corner regions, all four sides of the board have an odd number of board segments belonging to outer regions, so at least 2 outer regions have area $\frac{3}{2}$. The total area (of outer and corner regions) in this case is also at least $4 \cdot \frac{1}{2}+2 \cdot \frac{3}{2}+(2 N-6) \cdot 1=2 N-1$. If there would be no corner regions or exactly 1 corner region, then the total area of all outer and corner regions would be at least $1 \cdot \frac{1}{2}+(2 N-1) \cdot 1>2 N-1$. (We could have argued that these cases are actually impossible, but for the sake of our argument this is sufficient.) So the area of all non inner regions is at least equal to $2 N-1$. The remaining area is at most $N^{2}-2 N+1=(N-1)^{2}$, so there are at most $\frac{1}{2}(N-1)^{2}$ inner regions. This implies that there are at most $$ 2 N+\frac{(N-1)^{2}}{2}=\frac{(N+1)^{2}}{2} $$ regions when $N$ is odd. The following examples show that these numbers of regions can be obtained. Example: ![](https://cdn.mathpix.com/cropped/2024_06_05_95e557bc4ef4e666f168g-19.jpg?height=616&width=1306&top_left_y=1136&top_left_x=366) Answer: the smallest $K$ is $2 N$ and the largest is $\left\lfloor\frac{(N+1)^{2}+1}{2}\right\rfloor$. Remark: every configuration of chosen diagonals determines a set of paths (which may even not be paths but cycles): when you enter into a small square, you leave it on your left or on your right (the chosen diagonal determines that). So if you start in any region, in any square, and follow your path, only one of two possibilities happen: you leave the big square, or you return to the starting point and the path actually is a circle (and, with a chess argument, an even cycle). In the case where you leave the big circle, if you follow the path from the starting point into the opposite dirrection, you cannot return to this point but you also leave the big square so you get a path that starts and ends on the boundary of a big square. Of course every path/circle corresponds to a region. This approach in a way replaces the red-triangle argument from the official solution and the proof that the smallest area of inner regions is 2 . Solution 2. We make use of the generalized Euler's polyhedron formula $$ V+F=E+C+1 $$ Herein $V$ denotes the number of vertices, $E$ the number of edges, $F$ the number of faces (regions) and $C$ the number of connected components of a planar graph. We apply this formula to the graph whose vertices are the $(N+1)^{2}$ corner points of all the $N^{2}$ unit squares. The edges are the $4 N$ segments on the circumference and the $N^{2}$ drawn diagonals. Then we get for the number of faces (without the exterior face) $$ K=F-1=E-V+C=4 N+N^{2}-(N+1)^{2}+C=2 N-1+C $$ Since $C \geqslant 1$ we must have $K \geqslant 2 N$. We can easily achieve $C=1$ and $K=2 N$, for instance by choosing all the diagonals parallel to each other. Hence $2 N$ is the least possible value of $K$. In order to find an upper bound for $C$ we assign to every corner point its boundary distance, i. e. the smallest distance from the four sides of the $N \times N$ square. (The corner points with boundary distance $d$ lie on the circumference of a square of side length $N+1-2 d$, there are exactly $(N+1-2 d)^{2}-(N-1-2 d)^{2}=4(N-2 d)$ such points, except for $N=2 d$, in which there is exactly one such point - the midpoint of the board.) Furthermore to a connected component $Z$ of the graph we assign the minimal boundary distance $D(Z)$ of the corner points contained in $Z$. (Since all the corner points lie in the same connected component, there is exactly one component $Z_{0}$ such that $D\left(Z_{0}\right)=0$.) We now consider two neighbouring corner points both having boundary distance $d \geqslant 1$ and we observe that at least one of them must be connected to a point with boundary distance $d-1$. (Namely these two corner points are two vertices of a unit square whose other two vertices have boundary distance $d-1$. The diagonal drawn in this unit square is the desired connection.) That means that for $2 dA C$. Prove that there exists a point $D$ with the following property: whenever two distinct points $X$ and $Y$ lie in the interior of $A B C$ such that the points $B, C, X$, and $Y$ lie on a circle and $$ \angle A X B-\angle A C B=\angle C Y A-\angle C B A $$ holds, the line $X Y$ passes through $D$. Solution. Let $D$ be the point on $B C$ for which $A D$ is a tangent to the circumcircle of $A B C$. As we will show in the sequel, the point $D$ is as desired. ![](https://cdn.mathpix.com/cropped/2024_06_05_95e557bc4ef4e666f168g-21.jpg?height=808&width=1522&top_left_y=1109&top_left_x=244) Solution 1. We assume $B, C, X, Y$ lie on a circle in that order, the other case being similar. We compute the following equality $$ \begin{aligned} \angle A X Y-\angle D A Y & =\angle A X B-\angle Y X B-\angle D A B-\angle B A Y \\ & =\angle A X B-\angle Y C B-\angle A C B-\angle B A Y \\ & =\angle A X B-2 \angle A C B+\angle A C Y-\angle B A C+\angle Y A C \\ & =\angle A X B-2 \angle A C B-\angle B A C+\pi-\angle C Y A \\ & =\angle A X B-\angle A Y C+\angle C B A-\angle A C B=0 . \end{aligned} $$ So $A D$ is tangent to the circumcircle of triangle $\triangle A X Y$. Consequently $A D$ is the radical axis of the circumcircles of triangles $\triangle A X Y$ and $\triangle A B C$. On the other hand $B C$ is the radical axis of the circumcircles of triangles $\triangle B C X$ and $\triangle A B C$. By a well known theorem the radical axis of three circles intersect in one point, so $X Y$ passes through $D$. Solution 2. Let $X$ and $Y$ be two points satisfying the condition mentioned in the problem and let the line $D X$ meet the circumcircle of triangle $B X C$ for the second time in $Y^{\prime}$. It suffices to prove that $Y=Y^{\prime}$. Let us assume that the points $D, X$ and $Y^{\prime}$ are collinear in this order, the other case being similar. Due to $D X \cdot D Y^{\prime}=D B \cdot D C=D A^{2}$ the triangles $A D X$ and $Y^{\prime} D A$ are similar. Hence $$ \begin{aligned} \angle C Y^{\prime} A & =360^{\circ}-\angle A Y^{\prime} D-\angle D Y^{\prime} C=180^{\circ}-\angle D A X+\angle C B X \\ & =\left(180^{\circ}-\angle B A X\right)-\angle D A B+\angle C B X=\angle A X B+\angle X B A-\angle A C B+\angle C B X \\ & =\angle A X B+\angle C B A-\angle A C B \end{aligned} $$ Using the condition $$ \angle A X B-\angle A C B=\angle A Y^{\prime} C-\angle C B A $$ we get $\angle A Y C=\angle A Y^{\prime} C$, so $Y$ and $Y^{\prime}$ lie on the same circle through $A$ and $C$. On the other hand, $Y$ and $Y^{\prime}$ both lie on the circumcircle of $\triangle B C X$, therefore $Y=Y^{\prime}$. ## T-6 ## $\mathbf{G}$ Let $I$ be the incentre of triangle $A B C$ with $A B>A C$ and let the line $A I$ intersect the side $B C$ at $D$. Suppose that point $P$ lies on the segment $B C$ and satisfies $P I=P D$. Further, let $J$ be the point obtained by reflecting $I$ over the perpendicular bisector of $B C$, and let $Q$ be the other intersection of the circumcircles of the triangles $A B C$ and $A P D$. Prove that $\angle B A Q=\angle C A J$. ![](https://cdn.mathpix.com/cropped/2024_06_05_95e557bc4ef4e666f168g-23.jpg?height=1168&width=1294&top_left_y=735&top_left_x=384) Solution. Let $A I$ intersect the circumcircle of triangle $A B C$ for the second time at $T$. It is known that $T$ is the centre of the circumcircle of triangle $B I C$ and due to symmetry the point $J$ lies on this circle as well. Since $$ \angle B Q P=\angle A Q P-\angle A Q B=\pi-\angle A D P-\angle A C B=\angle D A C=\angle B A T=\angle B Q T $$ the points $T, P$, and $Q$ are collinear. Now let $T J$ intersect $B C$ at $S$. We have $I J \| B C$ and the triangle $J T I$ is isosceles, so $S T D$ is isosceles as well. The same applies to DPI and as their base angles are both equal to $$ \frac{\pi-\angle A C B+\angle C B A}{2} $$ we must have $\angle I T S=\angle I P S$ as well, meaning that the quadrilateral $I P T S$ is cyclic. It follows that $\angle S P T=\angle S I T$. Their angles being equal, the triangles $T A B$ and $T B D$ are similar, whence $$ \frac{|T D|}{|T B|}=\frac{|T B|}{|T A|} $$ In view of $|T D|=|T S|$ and $|T B|=|T I|=|T J|$ this yields $$ \frac{|T S|}{|T I|}=\frac{|T J|}{|T A|} $$ which proves $I S \| A J$. It follows that $\angle S I T=\angle J A T$, which in combination with the result of our third paragraph proves $$ \angle I A Q=\pi-\angle Q P D=\angle S P T=\angle J A T $$ Using $\angle T A C=\angle B A I$ we get $\angle J A C=\angle B A Q$. ## T-7 N Find all pairs of positive integers $(a, b)$ such that $$ a!+b!=a^{b}+b^{a} $$ Answer. $(a, b) \in\{(1,1),(1,2),(2,1)\}$ Solution. If $a=b$, the equation reduces to $a!=a^{a}$. Since $a^{a}>a!$ for $a \geqslant 2$, the only solution in this case is $a=b=1$. If $a=1$, the equation reduces to $b!=b$, which gives an additional solution $a=1, b=2$. We prove $a=b=1 ; a=1, b=2$ and $a=2, b=1$ are the only solution of the Diophantine equation. Assume $a, b$ is another solution satisfying $1a$ we have $p \left\lvert\, \frac{b!}{a!}\right.$ and hence, $\frac{b!}{a!}+1$ is coprime to $p$. Thus, the exponent in prime factorization of LHS equals the exponent of $p$ in prime factorization of $a$ !. It is well know, that this equals $$ \sum_{k=1}^{\infty}\left\lfloor\frac{a}{p^{k}}\right\rfloor=\left\lfloor\frac{a}{p}\right\rfloor+\left\lfloor\frac{a}{p^{2}}\right\rfloor+\left\lfloor\frac{a}{p^{3}}\right\rfloor+\ldots $$ We have $\sum_{k=1}^{\infty}\left|\frac{a}{p^{k}}\right|<\frac{a}{p}+\frac{a}{p^{2}}+\cdots=a\left(\frac{1}{p-1}\right) \leqslant a$. The exponent of $p$ in prime factorization of RHS is however at least $a$ since $p|a, p| b$ and $b>a$. This contradicts the assumption that $a, b$ is a solution. Therefore there are no solutions to the equation, when $a, b \geqslant 2$. ## T-8 N Let $n \geqslant 2$ be an integer. Determine the number of positive integers $m$ such that $m \leqslant n$ and $m^{2}+1$ is divisible by $n$. Answer. $D\left(2^{\alpha_{0}} p_{1}^{\alpha_{1}} p_{2}^{\alpha_{2}} \cdots p_{k}^{\alpha_{k}}\right)=2^{k}$ Solution 1. Let $D(n)$ be the number of positive integers $m$ such that $m \leqslant n$ and $m^{2}+1$ is divisible by $n$. No number of the form $m^{2}+1$ is divisible by 4 , so if 4 divides $n$, we have $D(n)=0$. It is also known that $D(n)=0$ if $n$ is divisible by some number of the form $4 k+3$. Furthermore, $D(2)=1$. 1. Assume first that $n=p$ is an odd prime of the form $4 k+1$. We show that $D(p)=2$. Lemma: If $p=4 k+1$, where $k$ is a positive integer and $p$ is a prime number, and if $S=\left\{x_{1}, \ldots, x_{p}\right\}$ is a complete residue system modulo $p$, then there exist exactly two elements $x \in S$ for which $x^{2} \equiv-1(\bmod p)$. First, we will prove that congruence equation $x^{2} \equiv-1(\bmod p)$ has at least one solution if $p \equiv 1(\bmod 4)$. Using Wilson's theorem, we have $$ \left(1 \cdot 2 \cdots \frac{p-1}{2}\right) \cdot\left((p-1)(p-2) \cdots\left(p-\frac{p-1}{2}\right)\right) \equiv\left(\left(\frac{p-1}{2}\right)!\right)^{2} \equiv-1 \quad(\bmod p) $$ thus $x=\left(\frac{p-1}{2}\right)$ ! is a solution. Furthermore, if $x_{i} \in S$ is a solution then $x_{j}=p-x_{i} \in S$ is also a solution. If $p=2 q+1$, exactly one of the numbers $x_{i}, x_{j}$ is smaller than or equal to $q$. We can assume that $x_{i} \leqslant q$. If given congruence equation had another solution $x_{k} \in S$, we could, by the same argument, assume that $x_{k} \leqslant q$. However, $x_{i}^{2} \equiv x_{k}^{2} \equiv-1(\bmod p)$ implies that $p$ divides $\left(x_{k}-x_{i}\right)\left(x_{k}+x_{i}\right)$, which is impossible since $x_{i}, x_{k} \leqslant q$. This completes the proof of lemma. 2. Now let $n=p^{k}$ be a prime power where $p$ is congruent to 1 modulo 4 . We will prove by induction that $D\left(p^{k}\right)=2$. Induction basis, the case for $k=1$, is the previous step. Assume that $D\left(p^{k}\right)=2$ for some positive integer $k$. Let $i$ and $j$ be those two integers less then $p^{k}$ such that $i^{2}+1$ and $j^{2}+1$ are divisible by $p^{k}$. Then all numbers less then $p^{k+1}$ that satisfy congruence equation $x^{2} \equiv-1\left(\bmod p^{k}\right)$ are the following numbers: $$ m p^{k}+i, \quad \text { for } m=0, \ldots, p-1 \quad \text { and } \quad m p^{k}+j, \quad \text { for } m=0, \ldots, p-1 $$ Exactly one of the numbers $\frac{\left(m p^{k}+i\right)^{2}+1}{p^{k}}$ (for $\left.m=0, \ldots, p-1\right)$ is divisible by $p$, i.e. exactly one among numbers $\left(m p^{k}+i\right)^{2}+1$ (for $m=0, \ldots, p-1$ ) is divisible by $p^{k+1}$ ). To prove that, assume the opposite - that there are two such numbers, namely $\left(m_{1} p^{k}+\right.$ $i)^{2}+1$ and $\left(m_{2} p^{k}+i\right)^{2}+1$. This means that number $$ \begin{aligned} & \frac{\left(m_{1} p^{k}+i\right)^{2}+1}{p^{k}}-\frac{\left(m_{2} p^{k}+i\right)^{2}+1}{p^{k}} \\ = & \frac{\left(m_{1} p^{k}+i-m_{2} p^{k}-i\right)\left(m_{1} p^{k}+i+m_{2} p^{k}+i\right)}{p^{k}} \\ = & \left(m_{1}-m_{2}\right)\left(p^{k}\left(m_{1}+m_{2}\right)+2 i\right) \end{aligned} $$ is divisible by $p$ which is impossible because neither $m_{1}-m_{2}$ nor $i$ are divisible by $p$. In the same way, we conclude that exactly one of the numbers $\left(m p^{k}+j\right)^{2}+1$ (for $m=$ $0, \ldots, p-1)$ is divisible by $p^{k+1}$. Therefore, $D\left(p^{k+1}\right)=2$. 3. Next, assume that $n=p^{a} q^{b}$ where $p$ and $q$ are two distinct prime numbers of the form $4 k+1$, for positive integers $k$, then $D\left(p^{a} q^{b}\right)=4$ for all positive integers $a$ and $b$. According to above, $D\left(p^{a}\right)=2$. Let $i$ and $j$ be those two positive integers smaller than $p^{a}$ such that $i^{2}+1$ and $j^{2}+1$ are both divisible by $p^{a}$. All numbers smaller than $p^{a} q^{b}$ that satisfy congruence equation $x^{2} \equiv-1\left(\bmod p^{a}\right)$ are the following: $$ m p^{a}+i \text { for } m=0, \ldots, q^{b}-1 \text { and } \quad m p^{a}+j \quad \text { for } m=0, \ldots, q^{b}-1 $$ Since $\left\{0,1,2, \ldots, q^{b}-1\right\}$ is a complete residue system modulo $q^{b}$, the same is true for $\left\{0, p^{a}, 2 p^{a}, \ldots,\left(q^{b}-1\right) p^{a}\right\}$ (because $p^{a}$ and $q^{b}$ are relatively prime), hence $T=\left\{i, p^{a}+\right.$ $\left.i, 2 p^{a}+i, \ldots,\left(q^{b}-1\right) p^{k}+i\right\}$ is a complete residue system modulo $q^{b}$, as well. Lemma implies that there are exactly two elements of the set $T$ that satisfy the congruence equation $x^{2} \equiv-1\left(\bmod q^{b}\right)$. In the same way, there are exactly two elements of the $\left\{j, p^{a}+j, 2 p^{a}+j, \ldots,\left(q^{b}-1\right) p^{a}+j\right\}$ that satisfy congruence equation $x^{2} \equiv-1\left(\bmod q^{b}\right)$. Therefore, $D\left(p^{a} q^{b}\right)=4$. Using the previous part inductively, we conclude that $D\left(p_{1}^{\alpha_{1}} \cdots p_{n}^{\alpha_{n}}\right)=2^{n}$ for distinct odd prime numbers $p_{i}, i=1,2, \ldots, n$. 4. Finally, we show that $D\left(p_{1}^{\alpha_{1}} \cdots p_{n}^{\alpha_{n}}\right)=D\left(2 p_{1}^{\alpha_{1}} \cdots p_{n}^{\alpha_{n}}\right)$, if $p_{i}, i=1,2, \ldots, n$ are distinct odd prime numbers, all congruent to 1 modulo 4 . Let $a=p_{1}^{\alpha_{1}} \cdots p_{n}^{\alpha_{n}}$. If $i_{1}, i_{2}, i_{3}, \ldots i_{2^{n}}$ are all positive integers less than $a$ that satisfy congruence equation $x^{2} \equiv-1(\bmod a)$, then all positive integers less than $2 a$ that satisfy that equation are the following: $$ \delta a+i_{j}, j=1,2,3, \ldots, 2^{n} \quad \text { for } \delta=0,1 $$ However, exactly one of the number $i_{j}^{2}+1$ and $\left(a+i_{j}\right)^{2}+1$ is even, which implies that $D\left(p_{1}^{\alpha_{1}} \cdots p_{n}^{\alpha_{n}}\right)=D\left(2 p_{1}^{\alpha_{1}} \cdots p_{n}^{\alpha_{n}}\right)$. Thus we conclude that $$ D\left(p_{1}^{\alpha_{1}} \cdots p_{n}^{\alpha_{n}}\right)=D\left(2 p_{1}^{\alpha_{1}} \cdots p_{n}^{\alpha_{n}}\right)=2^{n} $$ for distinct odd prime numbers $p_{i}, i=1,2, \ldots, n$. Solution 2. No number of the form $m^{2}+1$ is divisible by 4 , so if 4 divides $n$, we have $D(n)=0$. Also $D(2)=1$. Write $n=p_{0}^{\alpha_{0}} p_{1}^{\alpha_{1}} \cdots p_{k}^{\alpha_{k}}$ with $p_{0}=2, \alpha_{0} \in\{0,1\}$ and $p_{i}$ odd and $\alpha_{i} \geqslant 1$ for $i \geqslant 1$. The problem is to find the number of residue classes $m$ modulo $n$ with $m^{2} \equiv-1(\bmod n)$. It is clear that, $m^{2} \equiv-1(\bmod n)$ if and only if $m^{2} \equiv-1\left(\bmod p_{i}^{\alpha_{i}}\right)$ for all $i$. We use the following lemma. Lemma: Let $p$ be a prime number and $\alpha \geqslant 1$. Then the number of residue classes $m$ fulfilling $$ m^{2} \equiv-1 \quad\left(\bmod p^{\alpha}\right) $$ equals $$ \begin{cases}0 & \text { if } p \equiv 3 \quad(\bmod 4) \\ 1 & \text { if } p^{\alpha}=2 \\ 2 & \text { if } p \equiv 1 \quad(\bmod 4)\end{cases} $$ Proof of lemma: For $p^{\alpha}=2$, there is nothing to show. It is well-known that -1 is a quadratic residue modulo an odd prime $p$ if and only if $p \equiv 1(\bmod 4)$. We now assume $p \equiv 1(\bmod 4)$. It is also known (Hensel lifting) that if some $b$ is a quadratic residue modulo some odd prime $p$, then $b$ is also a quadratic residue modulo $p^{\alpha}$. Thus there is at least one residue class $m$ with $m^{2} \equiv-1\left(\bmod p^{\alpha}\right)$. Another residue class $r$ is also a solution $r^{2} \equiv-1\left(\bmod p^{\alpha}\right)$ if and only if $m^{2} \equiv r^{2}\left(\bmod p^{\alpha}\right)$ or equivalently $p^{\alpha} \mid$ $(m-r)(m+r)$. We have $\operatorname{gcd}(m+r, m-r) \mid 2 m$ which is coprime to $p^{\alpha}$. Thus $r \equiv \pm m$ $\left(\bmod p^{\alpha}\right)$. Thus $m^{2} \equiv-1\left(\bmod p^{\alpha}\right)$ has exactly two solutions. This proves the lemma. By the lemma, $\alpha_{0}$ does not influence the result. For each $1 \leqslant i \leqslant k$, there are two choices for $m$ modulo $p_{i}^{\alpha_{i}}$, thus there are $2^{k}$ choices for $m$ modulo $n$ by the Chinese remainder theorem.