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

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

时间:2017-05-23 13:21:37      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:ace   getchar   width   include   get   amp   height   ade   scanf   

同bzoj3930。

(日常盗题图)

技术分享

#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]);  
}

 

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

标签:ace   getchar   width   include   get   amp   height   ade   scanf   

原文地址:http://www.cnblogs.com/zcysky/p/6893538.html

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