Can the Repdigit 77...77 be the sum of two squares? 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?
 A: 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.
A: This is not an answer, but just an observation, which Martin had probably in mind. By Fermat we know that $n=x^2+y^2$ is the sum of two squares  iff the primes $p$ dividing $n$ with $p\equiv 3$ mod $4$ occur with even exponent. Suppose that $n=777\cdots 7$ has $k$ digits, and is the sum of two squares, $n=x^2+y^2$. 
Now we just study the first primes $p\equiv 3$ mod $4$ which possibly divide $n$. The prime $7$ is exceptional, because $7\mid n$ without any assumtion.
We have
$$
6\mid k \Rightarrow 7^2\mid n,\quad 7\cdot 6\mid k \Rightarrow 7^3\mid n, \quad 7^2\cdot 6\mid k \Rightarrow 7^4\mid n,\ldots 
$$
$$
2\mid k \Rightarrow 11 \mid n,\quad 2\cdot 11\mid k\Rightarrow 11^2\mid n,\quad 2\cdot 11^2\mid k \Rightarrow 11^3\mid n,\ldots
$$
There is enough data for the factorization of $n$ here, multiplying $111\cdots 1$ there with $7$. If we do this with several such primes, we can say at least something on $k$, the number of digits of $n$:
If $6\nmid k$, then $7^1$ is the exact power of $7$ dividing $n$;
i.e., $7^1\mid\mid n$. This contradicts Fermat's result. Hence we can conclude that $6\mid k$. It implies $3\mid k$, so that $9\mid k$, because otherwise $3^1\mid\mid n$, which is impossible. Also $2\mid k$, so that $11\mid n$. This implies $198=11\cdot2\cdot 3^2\mid k$, because otherwise $11^1\mid \mid n$, which is impossible. This is what Martin already had. We may continue now that in particular $33\mid k$, i.e., $67\mid n$. Since if not $3\cdot 11\cdot 67\mid k$ then $67^1\mid \mid n$, we arrive at $13266=2\cdot 3^2\cdot 11\cdot 67\mid k$, etc.
I have no idea whether this will continue, or whether we will finally find a possible $k$.
A: 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.
