代码拉取完成,页面将自动刷新
<snippet>
<content><![CDATA[
namespace math {
std::vector<int> prime;
std::vector<int> notprime;
template<typename T>
std::vector<std::array<T, 2>> catabolic(T n) {
assert(notprime.size() * 1ll * notprime.size() >= n);
std::vector<std::array<T, 2>> result;
for (auto &x : prime) {
if (x * 1ll * x > n) { break;}
if (n % x) { continue; }
result.push_back(std::array<T, 2>{x, 0});
while (n % x == 0) {
result.back()[1]++;
n /= x;
}
}
if (n > 1) { result.push_back(std::array<T, 2>{n, 1});}
return result;
}
void init_getprime(int N) {
notprime.resize(N + 1);
notprime[0] = notprime[1] = 1;
for (int i = 2; i <= N; i++) {
if (!notprime[i]) { prime.push_back(i); }
for (int j = 0; prime[j] * 1ll * i <= N; j++) {
notprime[prime[j] * i] = 1;
if (i % prime[j] == 0) { break; }
}
}
}
template<typename T>
void find_divisor(int steps, T divisor, std::vector<std::array<T, 2>> &p,
std::vector<T> &result) {
if (steps == p.size()) {
result.push_back(divisor);
return;
}
for (int i = 0; i <= p[steps][1]; i++, divisor *= p[steps][0]) {
find_divisor(steps + 1, divisor, p, result);
}
}
template<typename T>
std::vector<T> getdivisor(T n) {
std::vector<T> result;
std::vector<std::array<T, 2>> p = catabolic<T>(n);
find_divisor<T>(0, 1, p, result);
return result;
}
template<typename T>
std::vector<T> getdivisor(std::vector<std::array<T, 2>> &p) {
std::vector<T> result;
find_divisor<T>(0, 1, p, result);
return result;
}
template<typename T>
bool isprime(T query) {
if (notprime.size() > query) { return !notprime[query]; }
if (query >= 6) {
int remainder = query % 6;
if (remainder != 1 && remainder != 5) { return false; }
}
else if (query == 3 || query == 2 || query == 5) { return true; }
else { return false; }
assert(prime.size() && prime.back() * 1ll * prime.back() >= query);
for (int i = 0; i < prime.size(); i++) {
if (query % prime[i] == 0) { return false; }
if (prime[i] * 1LL * prime[i] > query) { break; }
}
return true;
}
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。