# $x(p − x)y(p − y)$ is square implies $x = y$

Given a prime $p > 2$ and positive integers $x,y \le \frac{p − 1}{2}$, prove that if $x(p − x)y(p − y)$ is a perfect square, then $x = y$.

This question was previously asked without context , and so was closed, but I did start towards a solution.

The primary insight is that the result depends on the unique representation of a prime as a sum of squares.

Obviously if that were not true we could have $m_0^2+n_0^2=m_1^2+n_1^2=p$. Then we could choose $x=m_0^2$ and $y=m_1^2$ as the lesser parts of those two different representations and with all contributing values being square, get a square that disproves the claim.

The other strand of proof that I did not succeed in completing was to eliminate the possibility that the various components might multiply together to give a square. Here are my thoughts on this so far:

Since $p$ prime, $x$ is coprime to $v:=(p-x)$ and $y$ is coprime to $w:=(p-y)$.

Find $g :=\gcd(x,y)$ and $h:=\gcd(v,w)$, and set $(a,b,c,d):=(x/g,y/g,v/h,w/h)$. If one of these terms is $1$ then all are, and $x=y$.

Assume that we have $a,b,c,d>1$. Then the expression of interest is $abcdg^2h^2$, which is square iff $abcd$ is square. The only possible common factors are in the pairs $(a,d)$ and $(b,c)$ so we would need $ad$ square and $bc$ square.

Can anyone either complete my proof or find a better way to demonstrate the truth of the opening claim?

This is the problem from the second stage of last year's Polish Mathematical Olympiad, see here. Below I present the official problem solution, from here.

Suppose the expression is a square, say $k^2$. Applying AM-GM inequality we quickly find $k<p^2/4$. On the other hand, from $x,y<p/2$, we find $k>xy$. Now we rewrite $$0=k^2-xy(p-x)(p-y)=(k-xy)(k+xy)-pxy(p-x-y),$$ from where $p\mid k-xy$ or $p\mid k+xy$.

Suppose first $k-xy=lp>0$. Then $$lp(lp+2xy)=lp(k+xy)=pxy(p-x-y),\\ p(xy-l^2)=xy(2l+x+y).$$ Since $x,y<p$, $p\mid 2l+x+y$. From $lp=k-xy<k<p^2/4$ we get $l<p/4$, and then $2l+x+y<2p/4+p/2+p/2=2p$, hence $2l+x+y=p$. However, then $p(xy-l^2)=pxy$, impossible given $l>0$.

Hence $k+xy=lp$ for some $l$. Like above, we get $p(xy-l^2)=xy(x+y-2l)$. From $lp=k+xy<p^2/4+(p/2)^2=p^2/2$ we get $l<p/2$. Hence $$p>x+y>x+y-2l>-2\cdot p/2=-p,$$ thus $x+y-2l=0$ (since it's divisible by $p$). Thus $p(xy-l^2)=0$, i.e. $xy=l^2$. Hence finally $$(x-y)^2=(x+y)^2-4xy=(2l)^2-4l^2=0$$ giving $x=y$.

• Wow. Nice trackdown skills. And a solution that shows the uniqueness of prime decomposition into squares as a weaker byproduct. – Joffan Oct 24 '17 at 18:33

$gcd(x,y)=n_1,gcd(x,p-y)=n_2$, $y$ and $p-y$ coprime, so $gcd(x,y(p-y))=n_1n_2$

Let $x=n_1n_2x',y=n_1y',p-y=n_2y''$, we have $x'(p − x)y'y''$ is square, so $x'$ is square.

In similar fashion, we can get: $x=n_1n_2a^2,y=n_1n_3c^2,p-x=n_3n_4b^2,p-y=n_2n_4d^2$

Now we have:

$p = n_1n_2a^2+n_3n_4b^2=n_1n_3c^2+n_2n_4d^2\tag1$

This can be solved in similar fashion as this answer.

# To be complete:

$p^2=(n_1n_2a^2+n_3n_4b^2)(n_1n_3c^2+n_2n_4d^2)$

so

$p^2=n_2n_3(n_1ac+n_4bd)^2+n_1n_4(n_2ad-n_3bc)^2\tag2$

$p^2=n_2n_3(n_1ac-n_4bd)^2+n_1n_4(n_2ad+n_3bc)^2\tag3$

By(1), we have

$(p - n_1n_2a^2)n_1n_2d^2=(p - n_1n_3c^2)n_1n_3b^2$

which implies

$p(n_3b^2-n_2d^2)=n_1(n_2ad-n_3bc)(n_2ad+n_3bc)\tag4$

From(4), $p$ divides $(n_2ad-n_3bc)$ or $(n_2ad+n_3bc)$. If $p$ divides $(n_2ad-n_3bc)$, then from (2) we get $(n_2ad-n_3bc)=0$, so from (4) $n_3b^2-n_2d^2=0$, so $p-x=p-y$. If $p$ divides $(n_2ad+n_3bc)$,then from (3) we get $(n_1ac-n_4bd)=0$, so $n_1ac=n_4bd$. $a$ and $b,d,n_4$ are coprime, so $a=1$.similarly $b=c=d=1$. Then $n_1=n_4=1$,$x=n_2,y=n_3, p=n_2+n3$, this contradicts $x,y\le\frac{p-1}{2}$.

• How do you deduce that x' is square? – Matt Oct 24 '17 at 17:47
• OK, an interesting way to proceed, but I don't quite see how it completes – Joffan Oct 24 '17 at 17:54
• @MattS x' is square because it is coprime with the rest of the term – lion Oct 24 '17 at 17:57
• But how is this a sum of two squares? How do you know that $n_1n_2a^2$ is a square? Is there any reason for $n_1n_2$ to be a square? Same for all the other summands. – Prasun Biswas Oct 24 '17 at 18:12
• @PrasunBiswas no, I am not saying $n_1n_2$ to be a square. I am just saying if we follow the calculation in that answer by take $p^2$ etc, we can get the result in similar but not identical fashion. – lion Oct 24 '17 at 18:16