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. Mysql的事务、视图、索引、备份和恢复

    事务 事务是作为单个逻辑工作单元执行的一系列操作,一个逻辑工作单元必须具备四个属性.即:原子性.一致性.隔离性.持久性,这些特性通常简称为ACID.   原子性(Atomicity) 事务是不可分割的 ...

  2. iOS device is locked/unlocked (判断手机屏幕是否锁屏)

    #import <notify.h> -(void)checkDeviceLockScreenState { int notify_token; notify_register_dispa ...

  3. [Codeforces]Codeforces Round #489 (Div. 2)

    Nastya and an Array 输出有几种不同的数字 #pragma comment(linker, "/STACK:102400000,102400000") #ifnd ...

  4. 《Java编程的逻辑》第四部分 文件

  5. jQuery——事件操作

    事件绑定 1.简单事件绑定 $("button").click(function () {})//可重复绑定,不会被层叠 2.bind():不推荐使用 $("button ...

  6. ubuntu下sudo命令不能使用问题

    不知道从什么时候开始,ctrl+alt+F1进入命令行之后,登录成功.使用sudo命令,不能使用....被坑了很久. 解决方法: 出现 [sudo ] username !!! 之后,在输入一遍 密码 ...

  7. yum进程被占用

    使用yum安装软件的时候出现,/var/run/yum.pid 已被锁定,PID 为 6503 的另一个程序正在运行的问题 [root@localhost mysql]# yum install gc ...

  8. 用C#在Visual Studio写Javascript单元测试

    1.在vs创建一个标准的单元测试工程 2.引用nuget包:Edge.js 我是用的是6.11.2版本 3.编写JsRunner类 using EdgeJs; using System; using ...

  9. c/c++排坑(3) -- c/c++中的switch语句

    switch语句的简单介绍 一个 switch 语句允许测试一个变量等于多个值时的情况.每个值称为一个 case,且被测试的变量会对每个 switch case 进行检查. switch(expres ...

  10. Sort HDU5884(二分+多叉哈夫曼树)

    HDU5884 Sort 题意:有n个序列要进行归并,每次归并的代价是两个序列的长度的和,要求最终的代价不能超过规定的T,求在此前提下一次能同时进行归并的序列的个数k. 思路:还是太单纯,看完题目一直 ...