• + 0 comments

    include

    using namespace std;

    int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int lcm(int x, int y ) {

    if(x==0)
        return 0;
    return (x*y)/gcd(x,y);
    

    }

    int main() { int n,m; cin>>n>>m; int a[n],b[m];

    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(int j=0; j<m; j++)
    {
        cin>>b[j];
    }
    
    
    int x=a[0];
    int y=b[0];
    
    for(int i=0; i<n; i++)
    {
    
         x=lcm(x,a[i]);
    
    
    }
    for(int j=0; j<m; j++)
    {
        y=gcd(y,b[j]);
    }
    
    
    //cout<<x<<endl;
    //cout<<y<<endl;
    
    //count the multiples of lcm of a that divides gcd of b
    int k=1;
    int count=0;
    int num=x;
    while(x<=y)
    {
    
        if(y%(x)==0) count++;
    
        k++;
        x=num*k;
    }
    

    cout<