I was wondering, whether the Repdigit $77...77$ (i.e. the number all of whose digits are $7$) can be the sum of two squares for some number of digits.


With elementary methods I could show, that if this can happen, the number of digits must be a multiple of $198$. The phenomenon that occurs (for the numbers I examined) is, that every time I have enough digits to "square" a prime divisor $p$ with $p \equiv 3 \mod 4$, I get new (and even more) single prime divisors $p \equiv 3 \mod 4$.


So I suppose, that none of these numbers can be written as the sum of two squares. Does anyone have an idea of how to prove (or disprove) that?



Can the Repdigit 77...77 be the sum of two squares?
We start with the following observation. Let $p$ be prime. Suppose that $p$ divides $AB$ with even exponent. Then if $(A,B)$ is prime to $p$, then $p$ divides exactly one of $A$ or $B$, and hence it also divides $A$ and $B$ with even
exponent.
It follows that if $AB$ is the sum of two squares and $(A,B) = 1$,
then $A$ and $B$ are the sum of two squares. Slightly more generally, we find:


**Proposition:** if $AB$ is the sum of two squares and $(A,B) = 1$ or $7$,
then either $A$ and $B$ are the sum of two squares or $7A$ and $7B$ are the sum of two squares. 


Now let $\displaystyle{A\_n:=777 \ldots 7777 = \frac{7}{9} \cdot (10^n - 1)}$.


If $A\_n$ is the sum of two squares, then so is $B\_n = 9 \cdot A\_n = 7(10^n - 1)$.


**Lemma:** The smallest integer $n$ such that $B\_n$ is the sum of two squares is odd.


**Proof:** By observation, the smallest such $n$ is $> 2$. Assume that $n = 2m$ with $m > 1$. We shall obtain a contradiction. We write


$$B\_{n} = B\_{2m} = 7(10^{2m} - 1) = 7(10^{m} - 1)(10^{m} + 1) = B\_{m} (10^m +1).$$


Now $(10^m - 1,10^m +1) = 1$, so $(B\_m,10^m +1) = 1$ or $7$. It follows from the proposition that $B\_m$ or $7 B\_m$ is
the sum of two squares. Since $m > 1$, it follows that $7 B\_m \equiv 3 \mod 4$ is not the sum of two squares, and so $B\_m$ is the sum of two squares. This contradicts the minimality of $n$. $\square$


Hence the smallest $n$ such that $B\_n$ is the sum of two squares is odd. However, this contradicts the fact (which you already observed) that if $n \not\equiv 0 \mod 6$ then $B\_n$ is exactly divisible by $7$ and so is not the sum of two squares.
Hence $A\_n$ can never be the sum of two squares.


