首页 > 其他 > 详细

BZOJ 3930 容斥原理

时间:2017-04-01 09:44:13      阅读:95      评论:0      收藏:0      [点我收藏+]

思路:

移至iwtwiioi    http://www.cnblogs.com/iwtwiioi/p/4986316.html

//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define int long long
const int mod=1000000007;
int n,k,l,h,f[100050];
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1)res=res*x%mod;
        x=x*x%mod,y>>=1;
    }return res;
}
signed main(){
    scanf("%lld%lld%lld%lld",&n,&k,&l,&h);
    for(int i=h-l;i;i--){
        int L=(l-1)/(k*i),R=h/(k*i);
        f[i]+=(pow(R-L,n)-R+L+mod)%mod;
        for(int j=2;i*j<=h-l;j++)(f[i]-=f[i*j])%=mod;
        f[i]=(f[i]+mod)%mod;
    }printf("%lld\n",(f[1]+(k>=l&&k<=h))%mod);
}

 

BZOJ 3930 容斥原理

原文:http://www.cnblogs.com/SiriusRen/p/6654388.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!