+ 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

12th Jul 2021, 9:56 AM
TCorn
10 ответов
+ 2
vrintle there is a bug in it. Here is my improved version for 9 digits https://code.sololearn.com/cI1X4iPDqnOy/?ref=app
14th Jul 2021, 6:31 AM
Oma Falk
+ 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.
12th Jul 2021, 10:24 AM
Rik Wittkopp
+ 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))
12th Jul 2021, 10:43 AM
Rik Wittkopp
+ 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.
12th Jul 2021, 12:08 PM
Oma Falk
12th Jul 2021, 1:12 PM
Oma Falk
12th Jul 2021, 1:47 PM
Oma Falk
+ 1
Here's my approach hope it will help you. https://code.sololearn.com/cI2fHBXIXI7t/?ref=app
13th Jul 2021, 8:29 PM
I Am a Baked Potato
+ 1
Oma Falk Are you sure that 9980899 is the largest in [2, 1e9] ?
14th Jul 2021, 5:51 AM
777
+ 1
Here is my approach, time complexity: negligible (yes! you heard it right) https://code.sololearn.com/ccH0qKkig2L6/?ref=app
14th Jul 2021, 5:57 AM
777
0
test each number as a string against itself flipped.
12th Jul 2021, 9:59 AM
Slick
Актуальное сегодня
HTML