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

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
题意:一个电话号码分成K块,每块的开头不能是b[i],每块应该是a[i]的倍数;
思路;将每块a[i]的总数求出来,再减去以b[i]开头的a[i]倍数的个数;
 #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define pi 4*atan(1)
//#pragma comment(linker, "/STACK:102400000,102400000")
#define maxn (1<<18)
const int N=;
ll a[N],b[N];
ll num[N];
ll f(ll x)
{
ll sum=;
for(ll i=;i<x;i++)
sum*=;
return sum;
}
int main()
{
ll x,y,z,i,t;
while(~scanf("%I64d%I64d",&x,&y))
{
ll base=f(y);
for(i=;i<x/y;i++)
scanf("%I64d",&a[i]);
for(i=;i<x/y;i++)
scanf("%I64d",&b[i]);
for(i=;i<x/y;i++)
{
ll num1=(base-)/a[i]+;
ll num2=((b[i]+)*(base/)-)/a[i]+(b[i]==?:);
ll num3=(b[i]*(base/)-)/a[i];
num3=max(0LL,num3);
num[i]=num1-num2+num3;
}
ll ans=;
for(i=;i<x/y;i++)
ans*=num[i],ans%=mod;
printf("%I64d\n",ans);
}
return ;
}

codeforces 300 div2 B.Pasha and Phone 容斥原理的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces 840C - On the Bench(dp/容斥原理)

    Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2500 的 D1C,可个人认为难度堪比某些 *2700 *2800. 不过嘛,*2500 终究还是 *2500,还是被我自己 ...

  8. Codeforces #442 Div2 F

    #442 Div2 F 题意 给出一些包含两种类型(a, b)问题的问题册,每本问题册有一些题目,每次查询某一区间,问有多少子区间中 a 问题的数量等于 b 问题的数量加 \(k\) . 分析 令包含 ...

  9. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

随机推荐

  1. Android获取文件的MD5值

    package my.bag; import java.io.File; import java.io.FileInputStream; import java.math.BigInteger; im ...

  2. OC开发_Storyboard——Core Data

    一 .NSManagedObjectContext 1.我们要想操作Core Data,首先需要一个NSManagedObjectContext2.那我们如何获得Context呢:创建一个UIMana ...

  3. 三维凸包求重心到面的最短距离(HDU4273)

    http://acm.hdu.edu.cn/showproblem.php?pid=4273 Rescue Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  4. 循环赛日常表算法(N可为奇数和偶数)

    一. 实验题目 设有n位选手参加网球循环赛,循环赛共进行n-1天,每位选手要与其他n-1位选手比赛一场,且每位选手每天必须比赛一场,不能轮空.试按此要求为比赛安排日程. 二.实验目的 1.深刻理解并掌 ...

  5. SQL中 decode()函数简介(转载)

    今天看别人的SQL时看这里面还有decode()函数,以前从来没接触到,上网查了一下,还挺好用的一个函数,写下来希望对朋友们有帮助哈! decode()函数简介: 主要作用:将查询结果翻译成其他值(即 ...

  6. 使用webmagic搭建一个简单的爬虫

    刚刚接触爬虫,听说webmagic很不错,于是就了解了一下. webmagic的是一个无须配置.便于二次开发的爬虫框架,它提供简单灵活的API,只需少量代码即可实现一个爬虫. 这句话说的真的一点都不假 ...

  7. Oracle管理监控之为11g asm磁盘组添加磁盘

    1.物理机挂在要添加的磁盘,虚拟机格式化虚拟硬盘 略 2.登录服务器:fdisk -l [root@node2 ~]# fdisk -l Disk /dev/sda: 107.3 GB, 107374 ...

  8. Scala数组和集合

    一.scala数组 数组定义1: var arr = new Array[String](3) String:存储的元素类型 3:存储3个元素 添加元素: arr(1) = "hello&q ...

  9. Python开发【Tornado】:简介与使用

    Tornado框架 简介: Tornado是使用Python编写的一个强大的.可扩展的Web服务器.它在处理严峻的网络流量时表现得足够强健,但却在创建和编写时有着足够的轻量级,并能够被用在大量的应用和 ...

  10. Django查询orm的前一天,前一周,一个月的数据

    利用datatime模块的datetime.timedelta()方法 计算时间差,以下是用法 唯一要注意的是数据库存储models.datefield字段是日期格式,所以比较的数据也是日期格式 #当 ...