#include <bits/stdc++.h>
using namespace std;
long long gcd(long long xx, long long yy) {
  while (yy != 0ll) {
    xx = xx % yy;
    swap(xx, yy);
  }
  return xx;
}
long long lcm(long long xx, long long yy) { return (xx / gcd(xx, yy)) * yy; }
int Power(int a, int x, int base = -1) {
  if (base == -1) {
    if (x == 1)
      return a;
    else if (x == 0)
      return 1;
    int temp = Power(a, x / 2);
    temp = temp * temp;
    if (x % 2 == 1)
      return temp * a;
    else
      return temp;
  } else {
    if (x == 1)
      return a % base;
    else if (x == 0)
      return 1;
    int temp = Power(a, x / 2, base);
    temp = (1ll * temp * temp) % base;
    if (x % 2 == 1)
      return (1ll * temp * a) % base;
    else
      return temp;
  }
}
const int MAXL = 1000 * 1000 + 1;
long long n, m, g, l;
long long res;
string X, Y;
int s[26][MAXL];
void DoSth() {
  l = lcm(X.length(), Y.length());
  g = gcd(X.length(), Y.length());
  for (int i = (0), _b = (X.length() - 1); i <= _b; i++) {
    int c = X[i] - 'a';
    s[c][i % g]++;
  }
}
void ReadInput() {
  cin >> n >> m;
  cin >> X >> Y;
}
void Process() {
  DoSth();
  res = 0ll;
  for (int i = (0), _b = (Y.length() - 1); i <= _b; i++) {
    int c = Y[i] - 'a';
    res = res + s[c][i % g];
  }
  res = n * X.length() / l * (l - res);
  cout << res;
}
int main() {
  ReadInput();
  Process();
  return 0;
}
