#include <bits/stdc++.h>
using namespace std;
template <typename T>
T Abs(T first) {
  return (first < 0 ? -first : first);
}
template <typename T>
T Sqr(T first) {
  return (first * first);
}
string plural(string s) {
  return (int((s).size()) && s[int((s).size()) - 1] == 'x' ? s + "en"
                                                           : s + "s");
}
const int INF = (int)1e9;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);
bool Read(int &first) {
  char c, r = 0, n = 0;
  first = 0;
  for (;;) {
    c = getchar();
    if ((c < 0) && (!r)) return (0);
    if ((c == '-') && (!r))
      n = 1;
    else if ((c >= '0') && (c <= '9'))
      first = first * 10 + c - '0', r = 1;
    else if (r)
      break;
  }
  if (n) first = -first;
  return (1);
}
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
long long lcm(int a, int b) { return ((long long)a * b / gcd(a, b)); }
int main() {
  if (0) freopen("in.txt", "r", stdin);
  long long N1, N2, lc, mult, ans = 0;
  int M1, M2;
  int i, j, g, g1, g2, s;
  int cnt1[26], cnt2[26];
  static bool vis1[1000000], vis2[1000000];
  static char S1[1000005], S2[1000005];
  scanf("%lld%lld", &N1, &N2);
  scanf("\n%s\n%s", &S1, &S2);
  M1 = strlen(S1);
  M2 = strlen(S2);
  lc = lcm(M1, M2);
  mult = N1 * M1 / lc;
  for (i = 0; i < M1; i++) {
    memset(cnt1, 0, sizeof(cnt1));
    memset(cnt2, 0, sizeof(cnt2));
    j = i;
    while (!vis1[j]) {
      vis1[j] = 1;
      cnt1[S1[j] - 'a']++;
      j = (j + M2) % M1;
    }
    j = i;
    while (!vis2[j]) {
      vis2[j] = 1;
      cnt2[S2[j] - 'a']++;
      j = (j + M1) % M2;
    }
    s = 0;
    for (j = 0; j < 26; j++) s += cnt2[j];
    for (j = 0; j < 26; j++) ans += (long long)cnt1[j] * (s - cnt2[j]);
  }
  cout << ans * mult << endl;
  return (0);
}
