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.

Sample test(s)
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为一个block(块)

第二行输入 n/k个数 表示  第i块中的数必须是a[i]的倍数

第三行输入 n/k个数 表示 第i块的首位不能为b[i]

注意 首位为0的处理!!!

还是水果A题 手速不行 B 字符串题目 要多练了

#include<bits/stdc++.h>
using namespace std;
#define N 1000000007
__int64 n,k;
__int64 a[100000];
__int64 b[100000];
__int64 re;
int main()
{
scanf("%I64d%I64d",&n,&k);
re=1;
for(__int64 i=1;i<=n/k;i++)
scanf("%I64d",&a[i]);
for(__int64 i=1;i<=n/k;i++)
scanf("%I64d",&b[i]);
for(__int64 i=1;i<=n/k;i++)
{
__int64 exm=1;
__int64 linshi=0;
for(int j=1;j<=k;j++)
exm*=10;
if(b[i]!=0)
linshi=linshi+(exm-1)/a[i]+1-(((b[i]+1)*(exm/10)-1)/a[i]-((b[i])*(exm/10)-1)/a[i]);
else
linshi=linshi+(exm-1)/a[i]-(exm/10-1)/a[i];
re=re*linshi;
re=re%N;
}
printf("%I64d",re);
return 0;
}

  

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 #330 (Div. 2)B. Pasha and Phone 容斥

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

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

  4. 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String

    题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...

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

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

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

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

  8. Codeforces Round #330 (Div. 2)

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

  9. Codeforces Round #337 (Div. 2) A. Pasha and Stick 水题

    A. Pasha and Stick   Pasha has a wooden stick of some positive integer length n. He wants to perform ...

随机推荐

  1. CSP201403-2:窗口

    引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...

  2. 聊一聊 Flex 中的 flex-grow、flex-shrink、flex-basis

    在使用 flex 布局的时候难以理解的是 flex-grow.flex-shrink.flex-basis 几个属性的用法,下面通过几个例子来演示. flex-basis flex-basis 用于设 ...

  3. Ext JS 6学习文档-第7章-图表

    Ext JS 6学习文档-第7章-图表 使用图表 本章中将探索在 ExtJS 中使用不同类型的图表并使用一个名为费用分析的示例项目结束本章所学.以下是将要所学的内容: 图表类型 条形图 和 柱形图 图 ...

  4. Python高级编程-多进程

    要让Python程序实现多进程(multiprocessing),我们先了解操作系统的相关知识. Unix/Linux操作系统提供了一个fork()系统调用,它非常特殊.普通的函数调用,调用一次,返回 ...

  5. Ubuntu 配置 ftp freemind adb

    . 1. 配置apt-get源 配置过程 : sudo vim /etc/profile 命令, 在后面添加下面的内容; 刷新配置文件 : source /etc/profie 命令; 刷新源 : s ...

  6. c#基类继承

    [ 塔 · 第 三 条 约 定 ] 编写一个多边形作为基类(成员:定点数)抽象方法(子类实现):体积.边长 正三角形类:成员 边长 长方形类:成员 长宽 using System; using Sys ...

  7. 【Docker 命令】- attach命令

    docker attach :连接到正在运行中的容器. 语法 docker attach [OPTIONS] CONTAINER 要attach上去的容器必须正在运行,可以同时连接上同一个contai ...

  8. 扩展SplitContainer控件

    效果图: 自定义控件实现代码: using System; using System.ComponentModel; using System.Drawing; using System.Window ...

  9. scala中的模式匹配

    基本语法 变量 match { case 值1 => 代码 case 值2 => 代码 ... case 值N if (...) => 代码 case _ => 代码 } 常量 ...

  10. 使用tc来控制网络流量

    https://blog.csdn.net/qinyushuang/article/details/46611709 tc实际操控网络的流量 解释网络tc的架构,从架构上分析tc,与netfilter ...