https://www.luogu.org/problem/P4213
1.杜教筛
2.min25筛
欧拉函数的通项公式:φ(n)=n*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中pi为n的质因数
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
//#include <tr1/unordered_map>
//#include <unordered_map>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define sfl(i) scanf("%lld",&i)
#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define prl(i) printf("%I64d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define inf 1e18
#define eps 1e-10
#define PI acos(-1.0)
#define lowbit(x) ((x)&(-x))
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define lson (rt<<1)
#define rson (rt<<1|1)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
template<typename T>inline void read(T &x)
{
x=0;
static int p;p=1;
static char c;c=getchar();
while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-48);c=getchar();}
x*=p;
}
//-----------------------------------------------
const int maxn=1e6+9;
const int maxm=5e6+9;
const int mod=1e9+7;
const int INV6=166666668;
ll n,sqrtn,prm[maxn],sump[maxn],cnt,g1[maxn],g2[maxn];
bool v[maxn];
void getP(int n)
{
cnt=0;
for(int i=2;i<=n;i++)
{
if(!v[i])
{
prm[++cnt]=i;
sump[cnt]=(sump[cnt-1]+i);
}
for(int j=1;j<=cnt&&prm[j]*i<=n;j++)
{
v[prm[j]*i]=1;
if(i%prm[j]==0) break;
}
}
}
ll val[maxn];
int id1[maxn],id2[maxn];
inline int get_id(ll x)
{
return ((x<=sqrtn)?id1[x]:id2[n/x]);
}
ll getphiS(ll x,ll y)
{
if(x<prm[y]||x<=1) return 0;
int k=get_id(x);
ll res=((g2[k]-g1[k])-(sump[y-1]-(y-1)));
for(int i=y;i<=cnt&&(ll)prm[i]*prm[i]<=x;++i)
{
ll t1=1,t2=prm[i];
for(int j=1;t2*prm[i]<=x;++j,t1=t2,t2*=prm[i])
{
ll tt1=t1,tt2=t2;
res=(res+getphiS(x/t2,i+1)*tt1*((ll)prm[i]-1)+tt2*((ll)prm[i]-1));
}
}
return res;
}
ll getmuS(ll x,ll y)
{
if(x<prm[y]||x<=1) return 0;
int k=get_id(x);
ll res=-g1[k]+y-1;
for(int i=y;i<=cnt&&(ll)prm[i]*prm[i]<=x;++i)
{
ll t1=prm[i];
res+=(-getmuS(x/t1,i+1));
}
return res;
}
int main()
{
FAST_IO;
int T;
read(T);
getP(100000+9);
while(T--)
{
read(n);
sqrtn=sqrt(n);
int tot=0;
for(ll i=1,j;i<=n;i=j+1)
{
j=n/(n/i);
ll w=n/i;
val[++tot]=w;
if(w<=sqrtn) id1[w]=tot;
else id2[n/w]=tot;
g1[tot]=w-1;
g2[tot]=w*(w+1)/2-1;
}
//滚动数组求 g(j,m)
for(int j=1;j<=cnt;j++)
{
for(int i=1;i<=tot&&(ll)prm[j]*prm[j]<=val[i];++i)
{
int k=get_id(val[i]/prm[j]);
g1[i]-=(g1[k]-(j-1));
g2[i]-=(ll)prm[j]*(g2[k]-sump[j-1]);
}
}
printf("%lld %lld\n",getphiS(n,1)+1,getmuS(n,1)+1);
//cout<<getphiS(n,1)+1<<" "<<getmuS(n,1)+1<<endl;
}
return 0;
}
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
#include <tr1/unordered_map>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define sfl(i) scanf("%I64d",&i)
#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define prl(i) printf("%I64d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-10
#define PI acos(-1.0)
#define lowbit(x) ((x)&(-x))
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define lson (rt<<1)
#define rson (rt<<1|1)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
template<typename T>inline void read(T &x)
{
x=0;
static int p;p=1;
static char c;c=getchar();
while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-48);c=getchar();}
x*=p;
}
const int maxn=5e6+9;
tr1::unordered_map<int,int>w1;
tr1::unordered_map<int,ll>w2;
bool check[maxn+10];
int prime[maxn/10];
int mu[maxn+10];
int phi[maxn+10];
int sum1[maxn+10];
ll sum2[maxn+10];
void Mobius_phi(int N)
{
mem(check,0);
mu[1]=1;
phi[1]=1;
int tot=0;
for(int i=2;i<=N;i++)
{
if(!check[i])
{
prime[tot++]=i;
mu[i]=-1;
phi[i]=i-1;
}
for(int j=0;j<tot;j++)
{
if(i*prime[j]>N) break;
check[i*prime[j]]=true;
if(i%prime[j]==0)
{
mu[i*prime[j]]=0;
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
else
{
mu[i*prime[j]]=-mu[i];
phi[i*prime[j]]=phi[i]*(prime[j]-1);
}
}
}
for(int i=1;i<=N;i++)
{
sum1[i]=sum1[i-1]+mu[i];
sum2[i]=sum2[i-1]+phi[i];
}
}
int djsmu(int x)
{
if(x<=5000000) return sum1[x];
if(w1[x]) return w1[x];
int ans=1;//h(x)前n项和
for(int l=2,r;l<=x;l=r+1)
{
r=x/(x/l);
ans-=(r-l+1)*djsmu(x/l);
}
w1[x]=ans;
return ans;
}
ll djsphi(int x)
{
if(x<=5000000) return sum2[x];
if(w2[x]) return w2[x];
ll ans=(ull)x*(x+1LL)/2LL;
for(int l=2,r;l<=x;l=r+1)
{
r=x/(x/l);
ans-=(ll)(r-l+1)*djsphi(x/l);
}
return w2[x]=ans;
}
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
Mobius_phi(5000000);
int T;
//cin>>T;
read(T);
while(T--)
{
int n;
//cin>>n;
read(n);
//cout<<djsphi(n)<<" "<<djsmu(n)<<endl;
printf("%lld %d\n",djsphi(n),djsmu(n));
}
return 0;
}