The number of palindromes that have the same value when read from either the left or right is called the number of palindromes. Of the number of palindromes represented by the product of two-digit numbers, the maximum is 9009 = 91 x 99.
Now, find the maximum number of palindromes represented by the product of three-digit numbers. http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%204
I reviewed the code I wrote. It seems that there is room for improvement in terms of primality test, because it is judged whether or not the remainder of division becomes 0.
The following algorithm was considered as an algorithm similar to the Eratostenes sieve.
target = seed * 1000 + int (str (seed) [:: -1])
, search the above list from the largest number, and finish when the number that becomes True is found.I implemented the above.
def erat_approach():
tl = [False]*(10**6)
for i in range(800,1000):
tl[i*800:i*1000:i] = [True]*200
t = 999
while 1:
n = t*1000+int(str(t)[::-1])
if tl[n]:
break
t-=1
print n
Result: Explosion was late (executed 100 times)
Recommended Posts