# BZOJ4805: 欧拉函数求和

BZOJ4805: 欧拉函数求和

10

32

## 题解Here!

$N\leq 2\times 10^9$！

# BZOJ3944: Sum

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#define MAXN 1700010
using namespace std;
map<int,long long> sum;
int k=0,prime[MAXN],mu[MAXN];
bool np[MAXN];
long long date=0;char c=0;
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9'){date=date*10+c-'0';c=getchar();}
return date;
}
void make(){
int m=MAXN-10;
mu[1]=1;
for(int i=2;i<=m;i++){
if(!np[i]){
prime[++k]=i;
mu[i]=-1;
}
for(int j=1;j<=k&&prime[j]*i<=m;j++){
np[prime[j]*i]=true;
if(i%prime[j]==0)break;
mu[prime[j]*i]=-mu[i];
}
}
for(int i=2;i<=m;i++)mu[i]+=mu[i-1];
}
long long solve_mu(long long n){
if(n<=MAXN-10)return mu[n];
if(sum.count(n))return sum[n];
long long ans=1;
for(long long i=2,last;i<=n;i=last+1){
last=n/(n/i);
ans-=1LL*(last-i+1)*solve_mu(n/i);
}
sum[n]=ans;
return ans;
}
long long solve_phi(long long n){
long long ans=0;
for(int i=1,last;i<=n;i=last+1){
last=n/(n/i);
ans+=1LL*(n/i)*(n/i)*(solve_mu(last)-solve_mu(i-1));
}
return (((ans-1)>>1)+1);
}
int main(){