How to resolve execution time out???? | Sololearn: Learn to code for FREE!


How to resolve execution time out????

I've to find 3 largest 9 digit palindrome prime number.I tried writing it in multiple ways.At last this is the code with minimum possible iteration I was able to come up with.But when I run the code still I'm getting the same execution timed out.Is there any other way to write this code?Can anyone help!

8/7/2020 3:28:48 PM


2 Answers

New Answer


Just add "return 0" or "break" after this "f = 0". Then you stop this for loop. Otherwise you will execute this loop for each number between 1 and your 9 digit input, what's a nightmare performance killer.


Your prime number check iterates first over each number (!) though you should really stop calculating its factors, if you've found one! return inside the for loop or break to stop: for(int i=1;i<=Math.sqrt(n);i++) { if(n%i==0) f=0; }