How to Optimise CPRIME - SPOJ

I just did CPRIME on Spoj, but my code ran in 15s. Does anyone have a faster approach?

Here is my code → Solution

You just need to write a faster sieve function. I get this Idea from This Post.
But I don’t have any idea, how this approach works.

@tanmoy_datta for above solution idea is simple ignore even numbers because only 2 is prime so now our space will be MAX / 2 and then run sieve accordingly. Hope you understand

Happy Coding :slight_smile: