B. Pasha and Phone
 

Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits.

Also Pasha has a number k and two sequences of length n / k (n is divisible by ka1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer.

To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1·10k - 1 + c2·10k - 2 + ... + ck.

Pasha asks you to calculate the number of good phone numbers of length n, for the given kai and bi. As this number can be too big, print it modulo 109 + 7.

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k.

The second line of the input contains n / k space-separated positive integers — sequence a1, a2, ..., an / k (1 ≤ ai < 10k).

The third line of the input contains n / k space-separated positive integers — sequence b1, b2, ..., bn / k (0 ≤ bi ≤ 9).

Output

Print a single integer — the number of good phone numbers of length n modulo 109 + 7.

Sample test(s)
input
6 2
38 56 49
7 3 4
output
8
 
Note

In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.

题意:给你n,k,n个ai,n个bi,  对于所有能整除ai的数中 位数小于等于k位,且最高位开头不以bi开头的数有几个,再取随机组合数

例:k=2     5是以0开头,不是以5开头

题解:我们可以算出1到n是x的倍数的个数有n/x个,那么减去一些不需要的数就是容斥了了,

///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a)); inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
const double PI = 3.1415926535897932384626433832795;
const double EPS = 5e-;
#define maxn 100000+500
#define mod 1000000007 ll num[maxn],a[maxn],b[maxn],kk; int main(){
ll n=read(),k=read();
ll tmp=; kk=k;
for(int i=;i<=k;i++)tmp*=; for(int i=;i<=n/kk;i++){
scanf("%I64d",&a[i]);
}
for(int i=;i<=n/kk;i++){
scanf("%I64d",&b[i]);
}
for(ll i=;i<=n/kk;i++){
num[i]=;
if(b[i]){
int T=;
for(int j=;j<=kk-;j++)b[i]*=,T*=;
ll H=(b[i]+(T-))/a[i]-(b[i]-)/a[i];
num[i]+=(tmp-)/a[i]-H;
}
else {
num[i]+=(tmp-)/a[i]-(tmp/-)/a[i];
}
if(b[i]==)num[i]--;
}
ll ans=;
for(int i=;i<=n/kk;i++){
ans=(ans*num[i])%mod;
}
cout<<ans<<endl;
return ;
}

代码

Codeforces Round #330 (Div. 2)B. Pasha and Phone 容斥的更多相关文章

  1. Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理

    B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/pr ...

  2. Codeforces Round #258 (Div. 2) E. Devu and Flowers 容斥

    E. Devu and Flowers 题目连接: http://codeforces.com/contest/451/problem/E Description Devu wants to deco ...

  3. Codeforces Round #330 (Div. 2) B. Pasha and Phone

    B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. Codeforces Round #428 (Div. 2) D. Winter is here 容斥

    D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...

  5. Codeforces Round #619 (Div. 2)C(构造,容斥)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int main(){ ios::syn ...

  6. Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和

    Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx ...

  7. 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String

    题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...

  8. Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理

    Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...

  9. Codeforces Round #337 (Div. 2) A. Pasha and Stick 数学

    A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...

随机推荐

  1. 研磨JavaScript系列(一):回归简单

    想要理解JavaScript,你得首先放下对象和类的概念,回到数据和代码的本原.编程世界只有数据和代码两种基本元素,而这两种元素又有着纠缠不清的关系.JavaScript就是把数据和代码都简化到最原始 ...

  2. [ SHOI 2014 ] 概率充电器

    \(\\\) \(Description\) 一个含\(N\)个元器件的树形结构充电器,第\(i\)个元器件有\(P_i\)的概率直接从外部被充电,连接\(i,j\)的边有\(P_{i,j}\)的概率 ...

  3. ubuntu上Hadoop三种运行模式的部署

    Hadoop集群支持三种运行模式:单机模式.伪分布式模式,全分布式模式,下面介绍下在Ubuntu下的部署 (1)单机模式 默认情况下,Hadoop被配置成一个以非分布式模式运行的独立JAVA进程,适合 ...

  4. StackOverflowError&OutOfMemoryError区别

    在Java虚拟机规范中,针对内存分配规定两种异常状况,即StackOverflowError和OutOfMemoryError. StackOverflowError:当线程请求的内存大小大于所配置的 ...

  5. DataTable And DataRow

    /// <summary> /// 将DataTable的字段名全部翻译为中文 /// </summary> /// <param name="table&qu ...

  6. Git的使用及托管代码到GitHub

    首先Git是一个开源的分布式版本控制工具,用git创建代码仓库. 仓库(Repository)是用于保存版本管理所需信息的地方,本地代码 提交到 代码仓库中,如果需要还可以 再推送到 远程仓库中. 所 ...

  7. Android studio USB连接失败

    Android studio USB连接失败,可能是因为adb的端口被占了,此时在其自带的cmd中输入netstat -aon|findstr "5037",并且启动任务管理器关掉 ...

  8. html——标签选择器

    交集选择器:标签+类(ID)选择器{属性:值:}.即要满足使用了某个标签,还要满足使用了类(id)选择器. <!DOCTYPE html> <html> <head> ...

  9. js 零碎

    function具有一个属性是length,表示希望接收到的命名参数的个数.可以通过arguments获取参数.arguments.callee表示函数本身,递归时有用,也可以通过arguments. ...

  10. vsftpd:500OOPS:vsftpd:refusingtorunwithwritablerootinsidechroot()错误的解决方法

    当我们限定了用户不能跳出其主目录之后,使用该用户登录FTP时往往会遇到这个错误: 500 OOPS: vsftpd: refusing to run with writable root inside ...