• + 0 comments

    Here is my c++ solution, you can see the explanation here : https://youtu.be/Xgchif6uHDU

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int gcd(int a, int b){
        if(b == 0) return a;
        return gcd(b, a%b);
    }
    
    int lcm(int a, int b){
        return a * b / gcd(a,b);
    }
    
    int main() {
        int n, m, e, l = 1, g = 0;
        cin >> n >> m;
        for(int i = 0; i < n; i++){
            cin >> e;
            l = lcm(l, e);
        }
        for(int i = 0; i < m; i++){
            cin >> e;
            g = gcd(g, e);
        }
        int res = 0;
        for(int c = l; c <= g; c+=l)if(g % c == 0) res ++;
        cout << res;
        return 0;
    }