求单个欧拉函数
根据定理:
\[\varphi(n) = n\cdot \prod_{p\mid n}{(1-\frac{1}{p})}
\]
直接分解质因数求即可,时间复杂度 \(\mathcal{O}(\sqrt n)\)。
代码
auto cal = [&](ll x){
ll res = x;
for (ll i=2;i*i<=x;i++){
if (x%i==0){
while (x%i==0){
x/=i;
}
res -= res/i;
}
}
if (x>1){
res -= res/x;
}
return res;
};

浙公网安备 33010602011771号