码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 2154(Crash的数字表格-莫比乌斯反演)

时间:2016-05-07 06:56:07      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:

题目:求i=1nj=1mlcm(i,j)

技术分享
技术分享

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case %d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<‘ ‘; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
                        For(j,m-1) cout<<a[i][j]<<‘ ‘;                        cout<<a[i][m]<<endl;                         } 
typedef long long ll;
typedef unsigned long long ull;
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
} 
#define MAXN (10000000+10)
ll modp = 20101009;
int p[MAXN],tot;
bool b[MAXN]={0};
int mul[MAXN]={0};
ll i2muli[MAXN],s[MAXN];
void make_prime(int n)
{
    tot=0; mul[1]=1;
    Fork(i,2,n)
    {
        if (!b[i]) p[++tot]=i,mul[i]=-1;
        For(j,tot)
        {
            if (i*p[j]>n) break;
            b[i*p[j]]=1;
            mul[i*p[j]]=-mul[i];
            if (i%p[j]==0) {
                mul[i*p[j]]=0;
                break;
            }  
        }
    }

    For(i,n) i2muli[i]=(ll)i*i%modp*mul[i];
    s[0]=0;
    For(i,n) s[i]=(s[i-1]+i2muli[i]+modp)%modp;
}
ll Sum(ll x,ll y){
    return ((1+x)*x/2%modp)*((1+y)*y/2%modp)%modp;
}
ll F(ll x,ll y)
{
    ll tmp=0;
    for(ll i=1;i<=min(x,y);){
        ll j=min(x/(x/i),y/(y/i));
        tmp=(tmp+Sum(x/i,y/i)*(s[j]-s[i-1]+modp)%modp)%modp;
        i=j+1;
    }   
    return tmp;
}
const int N = 1e7+1;
ll n,m;
int main()
{
//  freopen("bzoj2154.in","r",stdin);
//  freopen(".out","w",stdout);
    make_prime(N);
    cin>>n>>m;  
    ll tmp=0,x=n,y=m;
    for(ll i=1;i<=min(x,y);){
        ll j=min(x/(x/i),y/(y/i));
        tmp=(tmp+(ll)(i+j)*(j-i+1)/2%modp*F(n/i,m/i)%modp )%modp;
        i=j+1;
    }   
    cout<<tmp<<endl;
    return 0;
}

BZOJ 2154(Crash的数字表格-莫比乌斯反演)

标签:

原文地址:http://blog.csdn.net/nike0good/article/details/51335709

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!