codeLink : https://pastebin.com/vNLahq68
I am taking here global aray as n <= 5000000, because that prime no. can be really large and applying sieve of earathosnes but I am not getting right ans , please correct my code, where it is wrong
Deepak and primes
- Declare the primes array of type bool instead of int.
- Use long long int for all your loop variables - i,j and p.
- Line No.16 - change prime[i] = 0 to prime[j] = 0.
- Remove the cout statement in the loop.
CODE LINK : https://pastebin.com/q4Q4CH8Z
This is my modified code , but why will I change the array to bool int should also work find here because in conditional statement I am using logical operation in my previous code that should also work fine
@Divya_321
Sieve array requires you to store boolean data - true of false OR 1 or 0. Using int array would use up 8 times more space than required and that is a lot of wastage of space since we are making the sieve array of such a large size. Its possible some compiler won’t even allow you to make an array of so much space hence I suggested the modification.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.