I wrote a small script to find n-digit primes in the digits of e (in relation to that old Google ad):
import math
# First 251 digits of e
e_digits = ("2"
"7182818284 5904523536 0287471352 6624977572 4709369995"
"9574966967 6277240766 3035354759 4571382178 5251664274"
"2746639193 2003059921 8174135966 2904357290 0334295260"
"5956307381 3232862794 3490763233 8298807531 9525101901"
"1573834187 9307021540 8914993488 4167509244 7614606680")
e_digits = e_digits.replace(" ", "")
digits = int(raw_input("Number of digits: "))
print "Finding ", str(digits) + "-digit primes in the first", len(e_digits), "digits of e."
numbers = []
primes = []
# Creates list of numbers based on variable digits
for n in range(0,len(e_digits) - (digits - 1)):
test_number = e_digits[n:n+digits]
numbers.append(int(test_number))
# Checks each number for divisors smaller than its sqrt, then appends to list primes
for n in numbers:
n_sqrt = int(math.floor(math.sqrt(n)))
div = []
for i in range(2,n_sqrt+1):
if n % i == 0:
div.append(i)
if div == []:
primes.append(n)
print primes
However, when I set digits = 10, this is printed:
[7427466391L, 7413596629L, 6059563073L, 3490763233L, 2988075319L, 1573834187, 7021540891L, 5408914993L]
All of the list entries except for number six has been concatenated with an "L", and I have no clue why. The problem arises when I run the code in IDLE as well as in CMD, though only when appending ten digit integers using this specific code.
In the if-statement in the last for loop, the correct numbers are printed if I print n, or if I convert n to a string before appending. However, then converting to a integer again creates the same problem.
The problem also occurs with digits = 11, but not with digits < 10.
I cannot for the life of me find the error (or figure out if there is an error at all, really). Some advice on this would be greatly appreciated.