poj2478欧拉函数
打表欧拉函数,求2到n的欧拉函数和
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-12; const int N=1000000+10,maxn=500+100,inf=0x3f3f3f; ll euler[N]; void geteuler() { memset(euler,0,sizeof euler); euler[1]=1; for(int i=2;i<N;i++) { if(!euler[i]) { for(int j=i;j<N;j+=i) { if(!euler[j])euler[j]=j; euler[j]=euler[j]/i*(i-1); } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); geteuler(); ll n; while(cin>>n,n){ ll ans=0; for(ll i=2;i<=n;i++) ans+=euler[i]; cout<<ans<<endl; } return 0; } /********************* *********************/