【反演复习计划】【COGS2433】&&【bzoj3930,CQOI2015选数】爱蜜莉雅的冰魔法

同bzoj3930。

(日常盗题图)

Emilia

#include<bits/stdc++.h>
#define N 1000010  
#define yql 1000000007
#define ll long long
using namespace std;
int n;
ll m,l,r,k;ll f[N];
ll Pow(ll x,int y){
    ll ans=1;
    while(y){if (y&1) ans=ans*x%yql;  x=x*x%yql;  y>>=1;  }
    return ans;
}
ll read(){
    ll x=0;int f=1;char ch;
    do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return x*f;
}
int main(){
    freopen("aimiliyadeicemagic.in","r",stdin);
    freopen("aimiliyadeicemagic.out","w",stdout);
    scanf("%d",&n);k=read();l=read();r=read();
    for (ll i=r-l;i>=1;i--){  
        ll lx=(l-1)/(k*i),rx=r/(k*i);  
        f[i]=(Pow(rx-lx,n)-(rx-lx)+yql)%yql;  
        for (int j=2;i*j<=r-l;j++)  f[i]=(f[i]-f[i*j]+yql)%yql;  
    }  
    if (l<=k&&k<=r) f[1]++;  
    printf("%d\n",f[1]);  
}

 

posted @ 2017-05-23 12:31  zcysky  阅读(139)  评论(0编辑  收藏  举报