题目连接:http://codeforces.com/contest/595/problem/B
题目大意:
给你ai和bi,让你找到有多少个k位数,使得这个k位数不以bi开头且mod ai=0
处理n/k次,然后把所有的答案都乘起来。
解题思路:mid ai=0 的方案数减去bi开头的方案数。对bi=0的情况分类讨论。
/* ***********************************************
┆ ┏┓ ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃ ┃ ┆
┆┃ ━ ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃ ┃ ┆
┆┃ ┻ ┃ ┆
┆┗━┓ 马 ┏━┛ ┆
┆ ┃ 勒 ┃ ┆
┆ ┃ 戈 ┗━━━┓ ┆
┆ ┃ 壁 ┣┓┆
┆ ┃ 的草泥马 ┏┛┆
┆ ┗┓┓┏━┳┓┏┛ ┆
┆ ┃┫┫ ┃┫┫ ┆
┆ ┗┻┛ ┗┻┛ ┆
************************************************ */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <bitset>
using namespace std;
#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)
#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)
#define pb push_back
#define mp make_pair
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define MS0(X) memset((X), 0, sizeof((X)))
#define SelfType int
SelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);}
SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;}
#define Sd(X) int (X); scanf("%d", &X)
#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define all(a) a.begin(), a.end()
#define mem(x,v) memset(x,v,sizeof(x))
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
inline LL read(){LL ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
LL a[100005];
LL b[100005];
LL f[10];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int n,k;
n = read(),k = read();
f[0] = 1;
for(int i=1;i<=n/k;i++) a[i] = read();
for(int i=1;i<=n/k;i++) b[i] = read();
for(int i=1;i<=10;i++) f[i] = f[i-1]*10;
LL ans = 1;
for(int i=1;i<=n/k;i++)
{
LL t1 = (f[k]-1)/a[i] + 1; //是a[i]的倍数的数的个数。+1是全是0的情况
LL t2 = (f[k-1]-1)/a[i] + 1; //是a[i]的0倍的数的个数。
LL t3 = (f[k-1]*(b[i]+1)-1)/a[i] - (f[k-1]*b[i]-1)/a[i]; //是a[i]的倍数并且包含b[i]的数的个数
if(b[i]==0) ans *= t1 - t2;
else ans *= t1 - t3;
ans %= mod;
}
printf("%I64d\n",ans);
return 0;
}