1 #pragma GCC optimize("O3")
2 #include <cstdio>
3 #include <cstring>
4 #include <iostream>
5 #include <algorithm>
6 #include <queue>
7 using namespace std;
8 #define mod 1000000007
9 #define N 20050
10 #define M 15
11 long long n,k,num[N*10],size[N*10],ans;
12 struct NODE {
13 int x,y;
14 long long val;
15 NODE(int X=0,int Y=0) {x=X,y=Y,val=1ll*size[num[X]]*size[num[Y]];}
16 friend bool operator < (NODE a,NODE b) {return a.val<b.val;}
17 } ;
18 long long cnt,tmp[N*50],f[M][N*5][2];
19 int bit[M];
20 priority_queue <NODE> q;
21 bool cmp(int x,int y) {return size[x]>size[y];}
22 void dfs(int last,int len,long long now) {
23 if(len==bit[0]+1) {tmp[++cnt]=now; return ;}
24 if(!now) return ;
25 for(int i=last; i<=9; ++i) dfs(i,len+1,now*i);
26 }
27 int main() {
28 scanf("%lld%lld",&n,&k);
29 while(n) bit[++bit[0]]=n%10,n/=10;
30 dfs(0,0,1); tmp[++cnt]=0;
31 sort(tmp+1,tmp+cnt+1); cnt=unique(tmp+1,tmp+cnt+1)-tmp-1;
32 f[0][2][0]=1;
33 for(int i=0; i<=bit[0]; ++i) {
34 for(int j=1; j<=cnt; ++j) {
35 for(int h=0; h<=1; ++h) {
36 if(f[i][j][h]) {
37 for(int l=(i==0)?0:1; l<=9; ++l) {
38 f[i+1][lower_bound(tmp+1,tmp+cnt+1,tmp[j]*l)-tmp][h+l>bit[i+1]]+=f[i][j][h];
39 }
40 }
41 }
42 }
43 }
44 for(int i=1; i<=cnt; ++i) {
45 num[i]=i;
46 for(int j=1; j<bit[0]; ++j) size[i]+=f[j][i][0]+f[j][i][1];
47 size[i]+=f[bit[0]][i][0];
48 } sort(num+2,num+cnt+1,cmp);
49 q.push(NODE(2,2));
50 for(int i=0; !q.empty(); ) {
51 NODE temp=q.top(); q.pop();
52 ans=(ans+temp.val)%mod;
53 ++i;
54 if(i>=k) break;
55 if(temp.x!=temp.y) {
56 ans=(ans+temp.val)%mod;
57 ++i;
58 if(i>=k) break;
59 }
60 if(temp.x!=temp.y) q.push(NODE(temp.x+1,temp.y));
61 if(temp.x==2) q.push(NODE(temp.x,temp.y+1));
62 } printf("%lld\n",ans);
63 return 0;
64 }