B. Pasha and Phone
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 k) a1, 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 k, ai 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.

Examples
Input
6 2
38 56 49
7 3 4
Output
8
Input
8 2
1 22 3 44
5 4 3 2
Output
32400
Note

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

题意: 长度为n的手机号 按照每k位分块  n能够除尽k

第i块必须是ai的倍数 并且首位不能是bi  问有多少种满足条件的手机号

题解:容斥原理处理 统计每块满足条件的个数 累乘取模输出答案

每块满足条件的个数=是ai的倍数的个数 -(首位为bi并且是ai的倍数的个数)

注意b==0的处理 考虑后k-1位

注意计算首位为bi的并且是ai的倍数的个数的技巧

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<algorithm>
#define ll __int64
#define mod 1000000007
#define PI acos(-1.0)
using namespace std;
ll n,k;
ll a[];
ll b[];
int main()
{
scanf("%I64d %I64d",&n,&k);
for(ll i=;i<=n/k;i++)
scanf("%I64d",&a[i]);
for(ll i=;i<=n/k;i++)
scanf("%I64d",&b[i]);
ll ans=;
ll exm=;
for(int i=;i<=k;i++)
exm*=;
for(ll i=;i<=n/k;i++)
{
if(b[i]==)
ans=((exm-)/a[i]-(exm/-)/a[i])%mod*ans%mod;//考虑后k-1位
else
ans=((exm-)/a[i]-(((b[i]+)*exm/-)/a[i]-(b[i]*exm/-)/a[i])+)%mod*ans%mod;
}
printf("%I64d\n",ans);
return ;
}

Codeforces Round #330 (Div. 2) B 容斥原理的更多相关文章

  1. Codeforces Round #330 (Div. 1) A. Warrior and Archer 贪心 数学

    A. Warrior and Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594 ...

  2. Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力

    C. Edo and Magnets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/pr ...

  3. Codeforces Round #330 (Div. 2)D. Max and Bike 二分 物理

    D. Max and Bike Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/probl ...

  4. 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 ...

  5. Codeforces Round #330 (Div. 2) A. Vitaly and Night 暴力

    A. Vitaly and Night Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/p ...

  6. 随笔—邀请赛前训— Codeforces Round #330 (Div. 2) B题

    题意: 这道英文题的题意稍稍有点复杂. 找长度为n的数字序列有多少种.这个序列可以分为n/k段,每段k个数字.k个数可以变成一个十进制的数Xi.要求对这每n/k个数,剔除Xi可被ai整除的情况,剔除X ...

  7. 随笔—邀请赛前训— Codeforces Round #330 (Div. 2) Vitaly and Night

    题意:给你很多对数,要么是0要么是1.不全0则ans++. 思路即题意. #include<cstdio> #include<cstring> #include<iost ...

  8. Codeforces Round #330 (Div. 2)

    C题题目出错了,unrating,2题就能有很好的名次,只能呵呵了. 水 A - Vitaly and Night /***************************************** ...

  9. 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 ...

随机推荐

  1. MRCA|Wright–Fisher population genetic model|SNP rate

    (Panda has a high heterozygosity rate) 通过对mtDNA(为了预测SNP的密度)的分析,可知panda的多样性,当前全基因组数据才能完全建立模型. mitocho ...

  2. 对于无法激活的系统—使用rearm命令延长试用期

    1.首先安装后,有一个30天的使用期. 2.在30天试用期即将结束时,用rearm命令后重启电脑,剩余时间又回复到30天.微软官方文档中声明该命令只能重复使用3次,也说是说总共可以免费体验120天. ...

  3. AJAXA进行分页(2)

    查询功能是开发中最重要的一个功能,大量数据的显示,我们用的最多的就是分页. 在ASP.NET 中有很多数据展现的控件,比如用的最多的GridView,它同时也自带了分页的功能.但是我们知道用GridV ...

  4. 前端小记2——移动web解决方案

    面向用户级移动web解决方案: 1.代码结构规范 2.字体设置 body{ font-family: -apple-system, BlinkMacSystemFont, "PingFang ...

  5. 【Java】基本数据类型以及其转换

    整理了一下Java基本数据类型和面试可能涉及的知识.      字节数(byte)  位数(bit)  取值范围 整型  byte  1  8  -2^7 ~ 2^7 -1 short   2  16 ...

  6. css中让元素隐藏的多种方法

    { display: none; /* 不占据空间,无法点击 / } { visibility: hidden; / 占据空间,无法点击 / } { position: absolute; top: ...

  7. 2018.11.3 Nescafe18 T2 太鼓达人

    题目 背景 七夕祭上,Vani 牵着 cl 的手,在明亮的灯光和欢乐的气氛中愉快地穿行.这时,在前面忽然出现了一台太鼓达人机台,而在机台前坐着的是刚刚被精英队伍成员 XLk.Poet_shy 和 ly ...

  8. MultipartFile 动态决定是否上传文件,解决不上传文件报错

    controller 接收参数   用 HttpServletRequest 代替 @RequestParam()  接收参数 picFile 前台 传文件的参数名字  ,   这样 前段 传 nul ...

  9. PHP代码中出现中文乱码怎么办?

    header("Content-type:text/html;charset=utf-8"); //加上这个就OK //示例 : class WechatController ex ...

  10. Python知识点入门笔记——特色数据类型(字典)

    Python中字典是一些列键 (key) 值 (value) 对组成的,形式如下 {键1:值1,键2:值:2} 每个键值对用冒号隔开,每对之间用逗号隔开 键必须是唯一的,必须是不可变的,如字符串,数字 ...