#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main() {
  long long a, b;
  cin >> a >> b;
  string s1, s2;
  cin >> s1 >> s2;
  long long gc = gcd(s1.size(), s2.size());
  long long count = 0;
  for (int i = 0; i < gc; i++) {
    int j = i, siz1 = 0, siz2 = 00;
    set<char> sett, set2;
    vector<int> vecc(26);
    for (int l = 0; l < 26; l++) vecc[l] = 0;
    while (j < s1.size()) {
      sett.insert(s1[j]);
      vecc[s1[j] - 'a']++;
      siz1++;
      j += gc;
    }
    j = i;
    set<char>::iterator it = sett.begin();
    while (j < s2.size()) {
      it = sett.find(s2[j]);
      if (*it == s2[j]) {
        count += siz1 - vecc[*it - 'a'];
      } else {
        count += siz1;
      }
      j += gc;
    }
  }
  cout << count * gcd(a, b) << endl;
  return 0;
}
