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; + } + } + } + } +} +