Skip to content

CountPrimes.cpp - #276

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

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

Conversation

@harshit-3103

Copy link
Copy Markdown

No description provided.

@ksvijayan06 ksvijayan06 left a comment

Copy link
Copy Markdown

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

Comment thread C++/CountPrimes.cpp
int countPrimes(int n){
bool p[n+1] = {false};
//p[0] = false, p[1] = false;
for(int i=2;i<n;i++){

Copy link
Copy Markdown

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