#include <bits/stdc++.h>
int GCD(int a, int b) {
  if (b > a) return GCD(b, a);
  while (b != 0) {
    int t;
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}
int abs(int a) {
  if (a < 0) return -a;
  return a;
}
int ca[27][1000002];
int cb[27][1000002];
int main(void) {
  long long int n, m;
  char a[1000005], b[1000005];
  scanf("%I64d %I64d", &n, &m);
  scanf("%s %s", a, b);
  int la = strlen(a), lb = strlen(b);
  int gcd = GCD(la, lb);
  int i, j;
  for (i = 0; i < 27; i++)
    for (j = 0; j < gcd; j++) ca[i][j] = 0, cb[i][j] = 0;
  for (i = 0; i < la; i++) {
    int d = (int)a[i] - 97;
    ca[d][i % gcd]++;
  }
  for (i = 0; i < lb; i++) {
    int d = (int)b[i] - 97;
    cb[d][i % gcd]++;
  }
  long long int ans = (long long)la * lb / gcd;
  for (i = 0; i < 27; i++)
    for (j = 0; j < gcd; j++) ans -= (long long)ca[i][j] * cb[i][j];
  long long int w = n * gcd / lb;
  printf("%I64d\n", w * ans);
  return 0;
}
