This article is from the Puzzles FAQ, by Chris Cole chris@questrel.questrel.com and Matthew Daly mwdaly@pobox.com with numerous contributions by others.
How many primes are in the sequence 101, 10101, 1010101, ...?
arithmetic/digits/prime/101.s
Note that the sequence
101 , 10101, 1010101, ....
can be viewed as
100**1 +1, 100**2 + 100**1 + 1, 100**3 + 100**2 + 100**1 +1 ....
that is,
the k-th term in the sequence is
100**k + 100**(k-1) + 100**(k-2) + ...+ 100**(1) + 1
= (100)**(k+1) - 1
----------------
11 * 9
= (10)**(2k+2) - 1
----------------
11 * 9
= ((10)**(k+1) - 1)*((10)**(k+1) +1)
---------------------------------
11*9
 
Continue to: