-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Counting Coprimes Solution #4742
Conversation
closes #4702 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some style comments - i don't know the specific solution so won't comment on that
please split the solutions into multiple prs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please create separate prs before applying changes 🙏
thank you for your contribution!
for more information, see https://pre-commit.ci
@lext88 are you planning on splitting this PR up? i think it would probably be easier to review that way |
int main() { | ||
ll ans = 0; | ||
int N; | ||
vector<int> dp(MAX_X, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is dp initialized here?
also btw, vector autofills to 0.
for (int i = 2; i < MAX_X; i++) { | ||
if (is_prime[i]) { primes.push_back(i); } | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to be its own function?
title: Counting Coprime Pairs | ||
author: Alexis Tao | ||
--- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add an explanation?
const int MAX_X = 1e6 + 1; | ||
|
||
int main() { | ||
ll ans = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to justin's comment, initialize variables when you use them
// Lambda to initialize the sieve and populate the primes vector | ||
auto init = [&]() { | ||
fill(is_prime.begin() + 2, is_prime.end(), | ||
true); // Mark all numbers as prime initially (except 0 and 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting looks kind of weird here, why don't you just have the comment on a separate line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is also unnecessary? you only call the function once, just set is_prime[0]=is_prime[1]=false
|
||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 0; |
}; | ||
|
||
init(); // Initialize the sieve and primes | ||
cin >> N; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea move this cin up or move the n declaration down
initialize variables when you use them
This pull request has been automatically marked as stale because it has not had recent activity. Please address the requested changes and re-request reviews. Thank you for your contribution! |
Changes requested have not been made. Free free to create a new PR. |
Place an "x" in the corresponding checkbox if it is done or does not apply to this pull request.