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.
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).
Print a single integer — the number of good phone numbers of length n modulo 109 + 7.
6 2
38 56 49
7 3 4
8
8 2
1 22 3 44
5 4 3 2
32400
题意:一个电话号码分成K块,每块的开头不能是b[i],每块应该是a[i]的倍数;
思路;将每块a[i]的总数求出来,再减去以b[i]开头的a[i]倍数的个数;
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define mod 1000000007 5 #define inf 999999999 6 #define pi 4*atan(1) 7 //#pragma comment(linker, "/STACK:102400000,102400000") 8 #define maxn (1<<18) 9 const int N=100010; 10 ll a[N],b[N]; 11 ll num[N]; 12 ll f(ll x) 13 { 14 ll sum=1; 15 for(ll i=0;i<x;i++) 16 sum*=10; 17 return sum; 18 } 19 int main() 20 { 21 ll x,y,z,i,t; 22 while(~scanf("%I64d%I64d",&x,&y)) 23 { 24 ll base=f(y); 25 for(i=0;i<x/y;i++) 26 scanf("%I64d",&a[i]); 27 for(i=0;i<x/y;i++) 28 scanf("%I64d",&b[i]); 29 for(i=0;i<x/y;i++) 30 { 31 ll num1=(base-1)/a[i]+1; 32 ll num2=((b[i]+1)*(base/10)-1)/a[i]+(b[i]==0?1:0); 33 ll num3=(b[i]*(base/10)-1)/a[i]; 34 num3=max(0LL,num3); 35 num[i]=num1-num2+num3; 36 } 37 ll ans=1; 38 for(i=0;i<x/y;i++) 39 ans*=num[i],ans%=mod; 40 printf("%I64d\n",ans); 41 } 42 return 0; 43 }