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

#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
long long  f[10];long long a[100000+10], b[100000+10];int main(int argc, char *argv[]) {int i;f[0] = 1;for(i = 1; i <= 9; i++)f[i] = f[i-1] * 10;int n, k;scanf("%d%d", &n,&k);for(i = 0; i < n / k; i++)scanf("%lld", &a[i]);for(i = 0; i < n / k; i++)scanf("%lld", &b[i]);long long ans = 1;for(i = 0; i < n / k; i++){long long num1 = (f[k]-1) / a[i] + 1;long long num2 = (f[k-1]-1) / a[i] + 1;long long num3 = (f[k-1]*(b[i]+1)-1) / a[i] + 1 - (f[k-1]*b[i]-1) / a[i] - 1;if(b[i] == 0)ans *= num1-num2;elseans *= num1-num3;ans %= 1000000007;}printf("%lld\n",ans);return 0;
}

Pasha and Phone相关推荐

  1. W - Pasha and Phone CodeForces - 595B (收益颇丰的数学题

    Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Ea ...

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

  3. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and Phone Pasha has recently bought a new phone jPager and started adding his friends' phon ...

  4. Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题

    B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/prob ...

  5. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and Phone Pasha has recently bought a new phone jPager and started adding his friends' phon ...

  6. codeforces 435 B. Pasha Maximizes 解题报告

    题目链接:http://codeforces.com/problemset/problem/435/B 题目意思:给出一个最多为18位的数,可以通过对相邻两个数字进行交换,最多交换 k 次,问交换 k ...

  7. Coder-Strike 2014 - Finals (online edition, Div. 2) A. Pasha and Hamsters

    水题 #include <iostream> #include <vector> #include <algorithm>using namespace std;i ...

  8. 模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels

    题目传送门 1 /* 2 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0 3 很挫的判断四个方向是否OK 4 */ 5 #incl ...

  9. codeforces B. Pasha and String(贪心)

    题意:给定一个长度为len的字符序列,然后是n个整数,对于每一个整数ai, 将字符序列区间为[ai,len-ai+1]进行反转.求出经过n次反转之后的序列! 1 /* 2 思路1:将区间为偶数次的直接 ...

最新文章

  1. JAVA动态读取xml_Java动态生成和解析xml文件步骤详解
  2. 0902 - Preferences Permission
  3. [征求意见]团队发展、技术交流主题、团队机构
  4. linux查看cpu缓存大小,如何在Linux中获取CPU Cache的大小
  5. 未来的创业者和公司,一定要具备三大能力
  6. 使用tSQLt创建SQL单元测试实用程序过程
  7. linux持续检测进程脚本,用于检测进程的shell脚本代码小结
  8. IMCASH:2019年区块链不会风平浪静,至少还有10件事值得期待
  9. l298n电机哪一端为正_L298N控制直流电机正反转
  10. 水印相机定位不准确怎么办_水印相机怎么定位位置
  11. 相机存储卡不小心格式化怎么恢复呢?
  12. 情景英语-美国情景会话大全 精选
  13. 方舟生存进化服务器存档位置,方舟生存进化怎么转移存档
  14. WebRTC和APP互通连麦直播
  15. 途志:新主播让自己的直播热起来有什么技巧?
  16. Windows电脑加速小技巧(VIP典藏版)
  17. [后端开发]Http请求413错误解决方法
  18. 大连东软计算机专业全国排名,大连东软信息学院就业怎么样?全国前三,名不虚传!...
  19. Flink系列文档-(YY02)-Flink编程基础-入门示例
  20. 【手机投影】安卓手机投影到WIN10

热门文章

  1. 使用Spring进行不同开发所需要用到的包
  2. linux键盘输入重复,关于修改键盘输入
  3. linux 在线帮助,linux教程之在线帮助
  4. down redis集群_Redis总结(十)redis集群-哨兵模式
  5. 打印5列五颗星_13个Excel快捷打印技巧,让你熟练掌握打印机操作
  6. c语言使用指针改数组逆置,用指针作函数参数,编写函数,将一个整型数组中的元素全部逆置。...
  7. 多个mysql 环境_关于几个MySQL环境问题的对比
  8. centos7 nginx php整合,Centos7下,宿主机nginx配合docker环境的php-fpm
  9. Python+Flask+Echart+WordCloud:豆瓣爬虫项目的可视化数据
  10. 贝叶斯算法对文本进行分类实例