Finding $n$ such that $x_n$ is a prime number If the number $x_n$ is in the form of $1010101...1$ has $n$ ones .How to find each $n$ such that $x_n$ is a prime number 
 A: The answer is $x_n$ is prime $\iff n=2$:


*

*$101$ is prime.

*If $n$ is even then $101\mid x_n$ (see Mike's comment).

*If $n=2k+1$ then $x_n=\overbrace{11\ldots1}^n\times\overbrace{90909\ldots09}^{k \text{ nines}}1$.



Proof of (3):
From  Cameron Buie's comment (or by direct multiplication) it follows that 
$\color{blue}{11}\times \color{blue}{x_n}=\overbrace{11\ldots1}^{2n}=
\overbrace{\color{blue}{11\ldots1}}^{n}\times\color{blue}{1}\overbrace{\color{blue}{00\ldots0}}^{2k \text{ zeros}}\color{blue}{1}$. 
Since 
$\gcd(11,\overbrace{11\ldots1}^{n})=1$ ($n$ is odd) 
it follows that $\overbrace{11\ldots1}^{n}\mid x_n$ and $11\mid1\overbrace{00\ldots0}^{2k \text{ zeros}}1$.
Therefore $x_n$ is composite.
From 
$$\begin{array}{cc}
\overbrace{90909\ldots0909}^{k \text{ nines}}1&\\
90909\ldots090910\, & + \\
\text{__________________}&\\
1\underbrace{00000\ldots00000}_{2k \text{ zeros}}1\;\;\;\,&
\end{array}$$
we conclude
$$
11\times\overbrace{90909\ldots09}^{k \text{ nines}}1=(10+1)\times\overbrace{90909\ldots09}^{k \text{ nines}}1=
1\overbrace{00\ldots0}^{2k \text{ zeros}}1\Longrightarrow\\ 
x_n=
\overbrace{11\ldots1}^n\times\overbrace{90909\ldots09}^{k \text{ nines}}1.
$$
