C++ solution says Memoty Limit Exceeded on submission


Hi. In this prime sum problem, i had used sieve to generate all the primes but submission failed due to Memory Limit exceeding. I used the proper type for the variables too but couldn’t resolve the issue. Please help me find the bug.
Thank you.


Try to use minimum size boolean vector for sieve, It worked for me!!


yes it also worked for me…can you please tell why it is correct when we take bool


@subba-reddy_533. the size of integer is 4 bytes and of bool is 1 byte. As we only need a marker of 0 and 1, we should use boolean. But, when we use a vector of integer instead of boolean, we would be wasting 3bytes per vector data of memory which is unnecessary and occupies the entire space available to us for solving a large problem.


@rjkrsingh Thanks for the great observation about the difference in memory of integer and boolean array, I would have never thought about it if it wasn’t for your comment. I learnt a lot more from your comment than the actual problem itself.


Welcome brother && happy coding…