#include <bits/stdc++.h>
using namespace std;
char ca[1000005], cb[1000005];
long long la, lb, a, b;
struct str {
  long long tot;
  int val[26];
  str() {
    tot = 0;
    for (int i = 0; i < 26; ++i) val[i] = 0;
  }
} var;
long long gcd(long long g1, long long g2) {
  if (g1 % g2 == 0) return g2;
  return gcd(g2, g1 % g2);
}
int main() {
  cin >> a >> b >> ca >> cb;
  la = (long long)strlen(ca);
  lb = (long long)strlen(cb);
  long long gc = 1;
  if (la <= lb)
    gc = gcd(lb, la);
  else
    gc = gcd(la, lb);
  vector<str> va(gc, var), vb(gc, var);
  for (int i = 0; i < la; ++i) {
    int index = i % gc;
    va[index].val[ca[i] - 'a']++;
    va[index].tot++;
  }
  for (int i = 0; i < lb; ++i) {
    int index = i % gc;
    vb[index].val[cb[i] - 'a']++;
    vb[index].tot++;
  }
  long long ans = 0;
  for (long long i = 0; i < gc; ++i) {
    ans += va[i].tot * vb[i].tot;
    for (int j = 0; j < 26; ++j)
      if (va[i].val[j] > 0 && vb[i].val[j] > 0)
        ans -= (long long)va[i].val[j] * vb[i].val[j];
  }
  long long lcm = (la * lb) / gc;
  lcm = (a * la) / lcm;
  ans = ans * lcm;
  cout << ans << endl;
  return 0;
}
