#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

int main()
{
    long long int n,i,j,a,b,aa,bb,digit,digit1,ck=0,dk=0;
    while(scanf("%lld %lld", &a, &b)==2){
     aa = a;
    bb = b;
    while(a){
        digit = a%10;
        a/=10;
        if(digit==0) continue;
        else{
            if(aa%(digit)==0) ck++;
        }
    }

    while(b){
        digit1 = b%10;
        b/=10;
        if(digit1==0) continue;
        else{
            if(bb%(digit1)==0) dk++;
        }
    }
    cout<<ck+dk<<endl;
    ck=0,dk=0;
    }
}

