# 雅礼集训 Function

## 第一道分块题

Posted by yjjr's blog on January 13, 2018

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
{
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=1e6+6;
int n,prime[maxn],mu[maxn],d[maxn],s1[maxn],s2[maxn],cnt=0;
bool is_prime[maxn];
void getmu(){
mu[1]=1;
rep(i,2,maxn-6){
if(!is_prime[i])prime[++cnt]=i,mu[i]=-1;
rep(j,1,cnt){
if(prime[j]*i>maxn-6)break;
is_prime[prime[j]*i]=1;
if(i%prime[j]==0){mu[i*prime[j]]=0;break;}else mu[i*prime[j]]=-mu[i];
}
}
}
ll querys1(int x){
if(x<=maxn-6)return s1[x];
int y=round(sqrt(x)+1);ll re=0;
rep(i,1,y)re+=mu[i]*(x/(i*i));
return re;
}
ll querys2(int x){
if(x<=maxn-6)return s2[x];
ll re=0;
for(int i=1,j=1,k;i<=x;i=j+1){
k=x/i,j=x/k;
re+=(ll)(j-i+1)*k;
}
return re;
}
ll work(){
ll re=0;
for(int i=1,j=1,k;i<=n;i=j+1){
k=n/i,j=n/k;
re+=querys2(k)*(querys1(j)-querys1(i-1));
}
return re;
}
int main()
{
//freopen("function.in","r",stdin);
//freopen("function.out","w",stdout);
getmu();
rep(i,1,maxn-6)
rep(j,1,(maxn-6)/i)d[i*j]++;
rep(i,1,maxn-6)s1[i]=s1[i-1]+mu[i]*mu[i],s2[i]=s2[i-1]+d[i];