×

# Prime Palindrome HELP Part 3-Time Exceeded

 0 I've optimized the prime function and its still exceeding the time limit? Any ideas? Solution located at : http://www.codechef.com/viewsolution/3901718 asked 13 May '14, 09:40 0★tyrthor 5●2●10 accept rate: 0%

 1 Your solution is of complexity O(n*sqrt(n)) and n can go up to 10^6, thus your solution exceeds time limit. Since the number of prime palindromes, less than or equal to 1000000 is not very huge, you can preprocess it on your local machine and use it in your solution. (That has been done by most of the users with fastest execution times for that question). One optimization that you can try is storing all primes using a sieve and then checking for the palindromes. answered 13 May '14, 10:26 3.4k●19●43●77 accept rate: 16%
 2 Checking prime function takes too much time. Try checking isprime only if the number is a palindrome. if(ispalindrome(m)) if(isprime(m)) print m  answered 13 May '14, 10:39 4★abbas 411●8 accept rate: 28% Here is your accepted solution http://www.codechef.com/viewsolution/3901791 (13 May '14, 10:51) abbas4★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×3,820
×2,738
×1,918
×266
×195

question asked: 13 May '14, 09:40

question was seen: 1,305 times

last updated: 13 May '14, 10:51