[bzoj2226][Spoj 5971] LCMSum

Orz w_yqts
转换成欧拉函数..

#include 
using namespace std;
#define ll long long
#define N 1000001
int pn,pr[N],phi[N],flag[N];
ll f[N];
inline void solve()
{
    ll res=0LL;
    int n;
    scanf("%d",&n);
    for (int i=1;i*i<=n;++i)
    if (n%i==0)
    {
        res+=f[i];
        if (i*i!=n) res+=f[n/i];
    }
    printf("%lld\n",res*n);
}
int main()
{
    flag[1]=phi[1]=f[1]=1;
    for (int i=2;iif (!flag[i]) pr[++pn]=i,phi[i]=i-1;
        for (int j=1;j<=pn && pr[j]*i*pr[j]]=1;
            if (i%pr[j]==0) {phi[i*pr[j]]=phi[i]*pr[j];break;}
            phi[i*pr[j]]=phi[i]*phi[pr[j]];
        }
    }
    for (int i=2;i*phi[i]/2;
    int T;
    cin>>T;
    while (T--) solve();
}

你可能感兴趣的:(欧拉函数)