This documentation is automatically generated by online-judge-tools/verification-helper
#include "src/math/Euler-Function.hpp"
long long euler_function(long long x)
引数 $x$ に対して $x$ 以下の正整数の中で $x$ と互いに素なものの個数を返します。
64bit整数に収まる正整数をいれてください。
内部で zawa::factorize(x)
を呼び出しています。
$O(\sqrt{x})$
#pragma once
#include "factorize.hpp"
namespace zawa {
long long euler_function(long long x) {
long long res = x;
for (auto v : zawa::factorize(x)) {
res /= v.first;
res *= v.first - 1;
}
return res;
}
}// namespace zawa
#line 2 "src/math/Euler-Function.hpp"
#line 2 "src/math/factorize.hpp"
#include <vector>
namespace zawa {
std::vector<std::pair<long long, int>> factorize(long long x) {
std::vector<std::pair<long long, int>> res;
for (long long i = 2 ; i * i <= x ; i++) {
if (x % i) continue;
int cnt = 0;
while (!(x % i)) {
cnt++;
x /= i;
}
res.emplace_back(i, cnt);
}
if (x != 1) res.emplace_back(x, 1);
return res;
}
} // namespace zawa
#line 4 "src/math/Euler-Function.hpp"
namespace zawa {
long long euler_function(long long x) {
long long res = x;
for (auto v : zawa::factorize(x)) {
res /= v.first;
res *= v.first - 1;
}
return res;
}
}// namespace zawa