+ 3

# Help give me a hint of this challenge plz

Challenge: Find the largest palindromic-prime number in range 2 to 10**9 For those who don't know what palindromic-prime number is: -Palindromic number mean when you reverse it ,it will be equal to first value For example: 12321 is Palindromic number -Prime number mean a num that can be divisible by 1 and itself. So Palindromic number is a combination of two things above This is my code, but not work: https://code.sololearn.com/cwV36ZK8Rfs4/?ref=app I try to use bitmask but still not work

10 ответов

+ 2

vrintle there is a bug in it.
Here is my improved version for 9 digits
https://code.sololearn.com/cI1X4iPDqnOy/?ref=app

+ 2

Your code works up to 10**7, but I don't think the Sololearn system can support the number of iterations you require at 10**9.

+ 2

I am not sure if this will work, but maybe try this:
from sympy import primerange as pr, isprime as isp
#list of primes
print(list(pr(999888888,10**9)))
# bool is_prime
print(isp(999888943))

+ 2

The prime has 8 digits. edit.....9 digits
Last and first digit must be odd but not 5
So awxyzyxwa where a in 1,3,7,9
You have to check 4*10*10*10*10 numbers at maximum.
But surely one of first 500 might be a prime.
So begin with 999989999.
999979999
999959999...
Remember it is enough to check a divisor up to sqrt of number.
So u first might find all primes up to root(999999999) as possible divisor.(get list from internet or use python module)
With this, u might solve it also in SL.

+ 1

Ohhh 9 digits....
https://code.sololearn.com/crI7j07yr0iU/?ref=app

+ 1

Here's my approach hope it will help you.
https://code.sololearn.com/cI2fHBXIXI7t/?ref=app

+ 1

Oma Falk
Are you sure that 9980899 is the largest in [2, 1e9] ?

+ 1

Here is my approach, time complexity: negligible (yes! you heard it right)
https://code.sololearn.com/ccH0qKkig2L6/?ref=app

0

test each number as a string against itself flipped.