#include <bits/stdc++.h>
using namespace std;

int multiples(vector<int>&A, vector<int>&B){
    unordered_map<int,int> mppA, mppB;

    for(int x : A) mppA[x]++;
    for(int x : B) mppB[x]++;

    int maxB = *max_element(B.begin(), B.end());
    long long fin_count = 0;

    for(auto it : mppA){
        int current = it.first;
        int freqA = it.second;

        if(current == 0) continue;

        int count = 0;
        for(int j = current; j <= maxB; j += current){
            if(mppB.count(j))
                count += mppB[j];
        }

        fin_count += 1LL * count * freqA;
    }

    return fin_count;
}

int main(){
    int n, m;
    cin >> n >> m;

    vector<int> A(n), B(m);

    for(int i = 0; i < n; i++)
        cin >> A[i];

    for(int i = 0; i < m; i++)
        cin >> B[i];

    int count = multiples(A, B);
    cout << "Number of valid pairs: " << count << endl;

    return 0;
}
