2023-05-06发表2023-05-07更新算法几秒读完 (大约51个字)Template 线性筛 12345678910111213141516171819202122vector<int> minp, primes;void Init(int n) { minp.assign(n + 1, 0); primes.clear(); for (int i = 2; i <= n; i++) { if (minp[i] == 0) { minp[i] = i; primes.push_back(i); } for (auto p : primes) { if (i * p > n) { break; } minp[i * p] = p; if (p == minp[i]) { break; } } }} Templatehttps://www.kanoon.cn/2023/05/06/template/作者Kanoon发布于2023-05-06更新于2023-05-07许可协议#模板