1
0
Fork 0
This commit is contained in:
subcrip 2024-03-30 12:07:21 +08:00
parent ff3cf8618c
commit 5a0b6bc880
Signed by: subcrip
SSH Key Fingerprint: SHA256:dFPFi68d8C87YkFkEBU4TkcrYRySWpekRR1hbnDWUCw
1 changed files with 19 additions and 0 deletions

19
number/lpf.cc Normal file
View File

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