欧拉函数

代码摘自oi-wiki

void phi_table(int n, int* phi) {
  for (int i = 2; i <= n; i++) phi[i] = 0;
  phi[1] = 1;
  for (int i = 2; i <= n; i++)
    if (!phi[i])
      for (int j = i; j <= n; j += i) {
        if (!phi[j]) phi[j] = j;
        phi[j] = phi[j] / i * (i - 1);
      }
}
posted @ 2020-08-31 07:57  nao-nao  阅读(110)  评论(0编辑  收藏  举报