Codeforces 595B Pasha and Phone 【数学计数】

来源:互联网 发布:网络嗅探器用哪个好 编辑:程序博客网 时间:2024/05/24 01:36

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 12,..., k, the second block will be formed by digits from the phone number that are on positions k + 1k + 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 c1c2,...,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 0001 ≤ 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 238 56 497 3 4
output
8
input
8 21 22 3 445 4 3 2
output
32400
Note

In the first test sample good phone numbers are: 000000000098005600005698380000380098385600385698.




题意:现有一长度为n的空号码,给定整数k(满足n % k == 0)和具有n/k个元素的序列a[]和b[]。

定义一个电话号码是good:将长度n分成n/k块,要求第i块填a[i]的倍数且不能以b[i]开头,不够k位前面可以补0。

问你good 电话号码的个数%(1e9+7)。


思路:从前到后扫一遍就可以了。


偷懒用pow()函数,WA到死。。。


AC代码:


#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (100000+10)#define MAXM (50000000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;LL f[10];void getfac(){    f[0] = 1;    for(int i = 1; i <= 9; i++)        f[i] = f[i-1] * 10;}LL a[MAXN], b[MAXN];int main(){    getfac();    int n, k;    Ri(n); Ri(k);    for(int i = 0; i < n / k; i++)        Rl(a[i]);    for(int i = 0; i < n / k; i++)        Rl(b[i]);    LL ans = 1;    for(int i = 0; i < n / k; i++)    {        LL num1 = (f[k]-1) / a[i] + 1;        LL num2 = (f[k-1]-1) / a[i] + 1;        LL 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;        else            ans *= num1-num3;        ans %= MOD;    }    Pl(ans);    return 0;}


0 0
原创粉丝点击