#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 10000006
#define fi first
#define se second
#define pb push_back
int vis[N],prime[N],cnt;
int phi[N];
void Euler_phi(int n)
{
phi[1] = 1;
for(int i=2;i<=n;i++)
{
if(!vis[i])
{
prime[++cnt] = i;
phi[i] = i - 1;
}
for(int j=1;j<=cnt&&i*prime[j]<=n;j++)
{
vis[i*prime[j]] = 1;
if(i % prime[j] == 0)
{
phi[i*prime[j]] = phi[i] * prime[j];
break;
}
else phi[i*prime[j]] = phi[i] * (prime[j] - 1);
}
}
}
int main(){
Euler_phi(1000);
for(int i=1;i<=1000;i++) printf("%d\n",phi[i]);
return 0;
}
欧拉筛求欧拉函数模板
最新推荐文章于 2022-08-10 13:36:28 发布