_HHJ @ 2022-05-10 18:06:53
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long LL;
int k,n,y,ans;
vector<int> mul(vector<int>& a,int b)
{
vector<int> c;
int t=0;
for(int i=0;i<a.size()||t;i++)
{
if(i<a.size())t+=a[i]*b;
c.push_back(t%10);
t/=10;
}
while(c.size()>1&&c.back()==0)c.pop_back();
return c;
}
int main()
{
string a;
vector<int> A,B;
cin >> n;
while(n--)
{
cin >> a;
cin >> k;
for(int i=a.size()-1,j=1;i>=0;i--,j*=10)
{
A.push_back(a[i]-'0');
y=(a[i]-'0')*j;
}
for(int i=y-1;i>=1;i--)
{
A=mul(A,i);
}
for(auto i:A)
if(i==k)ans++;
printf("%d\n",ans);
ans=0;
A.clear();
}
}
by _HHJ @ 2022-08-22 23:20:30