首页 > 其他 > 详细

CodeForces 595B Pasha and Phone

时间:2016-05-07 21:59:27      阅读:234      评论:0      收藏:0      [点我收藏+]

转换成某区间上被k整除的数字有几个。

处理出每一段有几种,然后乘一下就是答案。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int maxn=100000+10;
long long MOD=1e9+7;
long long n,k;
long long a[maxn],b[maxn];
long long Ans[maxn],ans;
long long h[maxn];

long long GET(long long L,long long R,long long K)
{
    long long res;
    if(L<0&&R>0) res=R/K-L/K+1;
    else if(L==0&&R==0) res=1;
    else if(L==0)
    {
        res=1;
        if(R>=K) res=res+R/K-K/K+1;
    }
    else if(R==0)
    {
        res=1;
        swap(L,R); L=-L; R=-R;
        if(R>=K) res=res+R/K-K/K+1;
    }
    else if(L>0)
    {
        if(R>=K)
        {
            long long left;
            if(L%K!=0) left=L/K+1;
            else left=L/K;
            long long right=R/K;

            if(left>right) res=0;
            else res=right-left+1;
        }
        else res=0;
    }
    else
    {
        swap(L,R); L=-L; R=-R;
        if(R>=K)
        {
            long long left;
            if(L%K!=0) left=L/K+1;
            else left=L/K;
            long long right=R/K;

            if(left>right) res=0;
            else res=right-left+1;
        }
        else res=0;
    }
    return res;
}

int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=(int)n/k;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=(int)n/k;i++) scanf("%lld",&b[i]);

    long long top=0;
    for(int i=1;i<=k;i++) top=top*10+9;

    long long ans=1;

    for(int i=1;i<=n/k;i++)
    {
        long long f1=b[i],f2=b[i];
        for(int j=1;j<=k-1;j++)
        {
            f1=f1*10+0;
            f2=f2*10+9;
        }
        Ans[i]=GET(0,top,a[i])-GET(f1,f2,a[i]);
    }

    for(int i=1;i<=n/k;i++) ans=ans*Ans[i]%MOD;
    printf("%lld\n",ans);
    return 0;
}

 

CodeForces 595B Pasha and Phone

原文:http://www.cnblogs.com/zufezzt/p/5469160.html

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