#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int N = 1000005;
int n1, n2, d, sum, i, j, wyst[30];
long long res, n, m, w;
char t1[N], t2[N];
string s1, s2;
int nwd(int a, int b) {
  if (b == 0) return a;
  return nwd(b, a % b);
}
int main() {
  cin >> n >> m;
  scanf("%s %s", t1, t2);
  s1 = t1;
  s2 = t2;
  n1 = s1.size();
  n2 = s2.size();
  d = nwd(n1, n2);
  w = (n1 * 1LL * n2) / d;
  res = 0;
  for (i = 0; i < d; i++) {
    for (j = 0; j < 26; j++) wyst[j] = 0;
    for (j = i; j < n2; j += d) wyst[int(s2[j]) - 'a']++;
    sum = n2 / d;
    for (j = i; j < n1; j += d) res += (sum - wyst[int(s1[j]) - 'a']);
  }
  res = res * (n * n1 / w);
  cout << res << endl;
  return 0;
}
