TITLE: Can the Repdigit 77...77 be the sum of two squares?
QUESTION [17 upvotes]: 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?

REPLY [3 votes]: I like Troglodyte's answer, which I find surprising. I think it proves something rather more general, which I would like to record, though I am sure Troglodyte knows it. If $p \equiv 3$ (mod $4$) is a prime, and $a$ is an even integer which is a quadratic non-residue (mod $p$),
then either $a \equiv -1$ (mod $p$), or else $p(a^{n}-1)$ is not a sum of two squares for any positive integer $n.$
The proof is more or less the same, I just labour a few details. Assume that $a \not \equiv -1$ (mod $p$). Then (if there is any such integer), the least positive integer $n$ such that $p(a^{n}-1)$ is a sum of two squares must be even, as $a$ is a quadratic non-residue (mod $p$) and $p(a^{n}-1)$ must be divisible by $p^{2}$ as $p \equiv 3$ (mod $4$). Write $n = 2m.$ Then $m >1$ as $a \not \equiv \pm 1$ (mod $p$) by hypothesis. Now $p(a^{m}-1)$ is not a sum of two squares by the minimality of $n.$ However, $a^{m} -1 \equiv 3$ (mod $4$), so is not a sum of two squares either. Now $(a^{m}-1)p(a^{m}+1)$ is a sum of two squares. Hence $a^{m}-1$ can't be coprime to $p(a^{m}+1).$ Since $a^{m}-1$ is coprime to $a^{m}+1,$ we see that $a^{m}-1$ is divisible by $p.$ Now $\frac{a^{m}-1}{p}(a^{m}+1)$ is a product of two coprime integers and is a sum of two squares. Hence $\frac{a^{m}-1}{p}$ is a sum of two squares, and so is $p(a^{m}-1),$ a contradiction.