aboutsummaryrefslogtreecommitdiff
path: root/works/life/algorithm-experiment/1.2.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-02-28 23:13:39 +0800
committerYuqian Yang <crupest@crupest.life>2025-02-28 23:13:39 +0800
commitdc1f0c4c0096013799416664894c5194dc7e1f52 (patch)
tree2f5d235f778cd720f4c39ec3e56b77ba6d99f375 /works/life/algorithm-experiment/1.2.cpp
parent7299d424d90b1effb6db69e3476ddd5af72eeba4 (diff)
downloadcrupest-dc1f0c4c0096013799416664894c5194dc7e1f52.tar.gz
crupest-dc1f0c4c0096013799416664894c5194dc7e1f52.tar.bz2
crupest-dc1f0c4c0096013799416664894c5194dc7e1f52.zip
chore(store): move everything to store.
Diffstat (limited to 'works/life/algorithm-experiment/1.2.cpp')
-rw-r--r--works/life/algorithm-experiment/1.2.cpp73
1 files changed, 0 insertions, 73 deletions
diff --git a/works/life/algorithm-experiment/1.2.cpp b/works/life/algorithm-experiment/1.2.cpp
deleted file mode 100644
index ab49f6a..0000000
--- a/works/life/algorithm-experiment/1.2.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include <algorithm>
-#include <bitset>
-#include <cmath>
-#include <iomanip>
-#include <iostream>
-
-const int MAXN = 2000000000;
-long long pri[100000000];
-std::bitset<MAXN> vis;
-int cnt = 0;
-
-void init() {
- for (int i = 2; i < MAXN; ++i) {
- if (!vis[i]) {
- pri[cnt++] = i;
- vis[i] = true;
- } // vis[i]置为true或不置true都可以
- for (int j = 0; j < cnt; ++j) {
- if (i * pri[j] >= MAXN) //判断是否越界
- break;
- vis[i * pri[j]] = true; //筛数
- if (i % pri[j] == 0) //时间复杂度为O(n)的关键!
- break;
- }
- }
-}
-
-int main() {
- init();
-
- while (!std::cin.eof()) {
- long long n;
- std::cin >> n;
-
- bool b = false;
-
- if (n == 1 || n == 0) {
- continue;
- }
-
- if (std::binary_search(pri, pri + cnt, n)) {
- std::cout << n << '\n';
- continue;
- }
-
- for (int i = 0; i < cnt; i++) {
- if (n % pri[i] == 0) {
- b = true;
- break;
- }
- }
-
- if (b)
- continue;
-
- long long m = std::sqrt(n);
-
- for (long long i = pri[cnt - 1] + 2; i <= m; i += 2) {
- if (n % i == 0) {
- b = true;
- break;
- }
- }
-
- if (!b) {
- std::cout << n << '\n';
- }
-
- std::cin >> std::ws;
- }
-
- return 0;
-} \ No newline at end of file