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 ;
}

最新文章

  1. Nginx的安装配置
  2. 搭建高可用mongodb集群(四)—— 分片
  3. hdoj 1002 A+B(2)
  4. 《Unix网络编程》卷一(简介TCP/IP、基础套接字编程)
  5. AD 10 直接出 BOM 的漂亮效果
  6. Oracle修改字段长度以及计算天数
  7. Android 数据过滤器:Filter
  8. 看看android基础知识,谁帮我作答
  9. ES 13 - Elasticsearch的元字段 (_index、_type、_source、_routing等)
  10. 论文阅读笔记四十一:Very Deep Convolutional Networks For Large-Scale Image Recongnition(VGG ICLR2015)
  11. Java 线程方法
  12. Docker(三)Docker是如何工作的
  13. 超级有用的15个mysqlbinlog命令
  14. ubuntu文件名乱码convmv和iconv
  15. 关于string.Template的简单介绍
  16. QTP之回放模式(ReplayType)
  17. a标签--超链接
  18. leetcode 有效的括号
  19. (C/C++) 指向函數的指標
  20. HDU4788_Hard Disk Drive

热门文章

  1. 电力项目十七--数据字典首页JS添加和删除表格
  2. Python 自学积累(二)
  3. Centos6.5安装JDK环境
  4. java 中的&amp; &amp;&amp;区别以及 C++ 中&amp; &amp;&amp;的区别
  5. Apache POI 读写 Excel 文件
  6. You don&#39;t have permission to access
  7. python bug the C library strftime function.
  8. mongoexport
  9. talib 中文文档(九):# Volatility Indicator Functions 波动率指标函数
  10. Django - ORM - 进阶