# Bzoj2154 crash的数字表格

Posted by yjjr's blog on December 15, 2017 1 minutes to read

# 题目

Description

Sample Output 122

【数据规模和约定】

100%的数据满足N, M ≤ 10^7。

# 分析

$F(x,y)=\sum_{i=1}^{min(x,y)} i^2\mu(i)Sum(\lfloor x/i \rfloor ,\lfloor y/i \rfloor)$

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#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 mod 20101009
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=1e7+6;
int cnt,mu[maxn],prime[maxn],s[maxn];
ll ans=0,n,m;
bool is_prime[maxn];
ll sum(ll x,ll y)
{
return ((x*(x+1)/2)%mod)*((y*(y+1)/2)%mod)%mod;
}
void gets()
{
mu[1]=1;
rep(i,2,min(n,m))
{
if(!is_prime[i])prime[++cnt]=i,mu[i]=-1;
for(int j=1;j<=cnt&&prime[j]*i<=min(n,m);j++)
{
is_prime[prime[j]*i]=1;
mu[prime[j]*i]=-mu[i];
if(i%prime[j]==0){mu[prime[j]*i]=0;break;}
}
}
for(ll i=1;i<=min(n,m);i++)
s[i]=(s[i-1]+(i*i*mu[i])%mod)%mod;
}

ll F(ll x,ll y)
{
ll ans=0,last;
for(ll i=1;i<=min(x,y);i=last+1)
{
last=min(x/(x/i),y/(y/i));
ans=(ans+(s[last]-s[i-1])*sum(x/i,y/i)%mod)%mod;
}
return ans;
}
int main()
{