We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Anyone else who cried after solving this?
I tried to solve this for 2 hours. Time out. Always.
So, I tried to use dyanmic stack in CPP to store already found even numbers... Still the last one gave me timeout.
Solution ?
1) Add 2 and 3 to stack.
2) If n <= Size of stack, get item at position n and output answer
3) Else, start from last element of stack, check if prime
4) To check for prime, recursively divide from each element in stack. If remainder 0 for any element in stack, not a prime. Break loop
5) If Prime, add to stack
6) Search only odd numbers
That's it.
Now the last one which always timed out gave result in 0.3 seconds.
Project Euler #7: 10001st prime
You are viewing a single comment's thread. Return to all comments →
Anyone else who cried after solving this? I tried to solve this for 2 hours. Time out. Always.
So, I tried to use dyanmic stack in CPP to store already found even numbers... Still the last one gave me timeout.
Solution ?
That's it. Now the last one which always timed out gave result in 0.3 seconds.