Created
February 10, 2026 17:13
-
-
Save dgodfrey206/ea359bce2f7c822f425e509a8a8bf738 to your computer and use it in GitHub Desktop.
What is the 10001st prime number?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| #include <cassert> | |
| using namespace std; | |
| int main() { | |
| int n = 10001; | |
| int limit = n/2; | |
| vector<int> prime; | |
| while (true) { | |
| limit *= 2; | |
| prime.resize(limit + 1, 1); | |
| for (int i = 2; i * i <= limit; i++) { | |
| if (prime[i]) { | |
| for (int k = i * i; k <= limit; k += i) { | |
| prime[k] = 0; | |
| } | |
| } | |
| } | |
| int lastPrime = 1; | |
| int count = 0; | |
| for (int i = 2; i <= limit; i++) { | |
| if (prime[i]) { | |
| count++; | |
| lastPrime = i; | |
| } | |
| if (count == n) { | |
| break; | |
| } | |
| } | |
| if (count == n) { | |
| cout << lastPrime << '\n'; | |
| break; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment