From 5a0b6bc880cde939fc2fd07a9115ae4e9d0a8379 Mon Sep 17 00:00:00 2001 From: subcrip Date: Sat, 30 Mar 2024 12:07:21 +0800 Subject: [PATCH] backup --- number/lpf.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 number/lpf.cc diff --git a/number/lpf.cc b/number/lpf.cc new file mode 100644 index 0000000..d5a788b --- /dev/null +++ b/number/lpf.cc @@ -0,0 +1,19 @@ +constexpr int N = 1e7 + 10; + +int lpf[N]; + +void era(int n) { + lpf[0] = lpf[1] = -1; + for (int i = 2; i <= n; ++i) lpf[i] = i; + for (int i = 2; i <= n; ++i) { + if (lpf[i] == i) { + if ((ll)i * i > n) continue; + for (int j = i * i; j <= n; j += i) { + if (lpf[j] == j) { + lpf[j] = i; + } + } + } + } +} +