Advertisement
Dmaxiya

寻找质数 参考代码

Apr 12th, 2025
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 1000 + 100;
  6. int cnt;
  7.  
  8. bool isPrime(int x) {
  9.     if (x < 2) {
  10.         return false;
  11.     }
  12.     for (int i = 2; i <= x / i; ++i) {
  13.         if (x % i == 0) {
  14.             return false;
  15.         }
  16.     }
  17.     return true;
  18. }
  19.  
  20. int main() {
  21. #ifdef ExRoc
  22.     freopen("test.txt", "r", stdin);
  23. #endif // ExRoc
  24.  
  25.     for (int i = 0; i < 100000; ++i) {
  26.         if (isPrime(i)) {
  27.             ++cnt;
  28.             if (cnt == 2025) {
  29.                 cout << i << endl;
  30.                 return 0;
  31.             }
  32.         }
  33.     }
  34.  
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement