#include <bits/stdc++.h> using namespace std; int P[40005]={1,1},phi[40005]; vector<int> prime; void getphi(int n){ for(int i=2;i<=n;i++){ if(!P[i])prime.push_back(i),phi[i]=i-1; for(int j=0;j<prime.size()&&prime[j]*i<=n;j++){ if(i%prime[j])phi[i*prime[j]]=phi[i]*(prime[j]-1); else phi[i*prime[j]]=phi[i]*prime[j]; P[i*prime[j]]=1; if(!i%prime[j])break; } } } int main(){ int n,ans=0; cin>>n; getphi(n-1); return 0; }
时间: 2024-11-03 01:35:43