Skip to content

Comments

CountPrimes.cpp#276

Open
harshit-3103 wants to merge 1 commit intoAditya-devp:mainfrom
harshit-3103:main
Open

CountPrimes.cpp#276
harshit-3103 wants to merge 1 commit intoAditya-devp:mainfrom
harshit-3103:main

Conversation

@harshit-3103
Copy link

No description provided.

Copy link

@ksvijayan06 ksvijayan06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR. Please optimize the code

int countPrimes(int n){
bool p[n+1] = {false};
//p[0] = false, p[1] = false;
for(int i=2;i<n;i++){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of line no. 7 for loop you can initialize p[n+1] = {true} then
p[0] = false;
p[1] = false;
so we can save the unnecessary iteration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants