#include <bits/stdc++.h>
using namespace std;
const int NA = 1000000, NB = 1000000, A = 26;
char aa[NA + 1], bb[NB + 1];
int ka[A], kb[A];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  long long ma, mb;
  cin >> ma >> mb >> aa >> bb;
  int na = strlen(aa), nb = strlen(bb);
  int d = gcd(na, nb);
  long long m = (long long)na / d * nb;
  long long k = m;
  for (int r = 0; r < d; r++) {
    fill(ka, ka + A, 0);
    fill(kb, kb + A, 0);
    for (int i = r; i < na; i += d) {
      int a = aa[i] - 'a';
      ka[a]++;
    }
    for (int j = r; j < nb; j += d) {
      int b = bb[j] - 'a';
      kb[b]++;
    }
    for (int a = 0; a < A; a++) k -= (long long)ka[a] * kb[a];
  }
  k *= ma * na / m;
  cout << k << '\n';
  return 0;
}
