#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  if (x < 0)
    return -x;
  else
    return x;
}
int s[1000100][26];
long long N, M, L;
int n, m, d;
char x[1000100], y[1000100];
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int main() {
  scanf("%I64d%I64d", &N, &M);
  scanf("%s", x);
  scanf("%s", y);
  n = strlen(x);
  m = strlen(y);
  if (n < m) {
    for (int i = 0; i < m; ++i) swap(x[i], y[i]);
    swap(n, m);
    swap(N, M);
  }
  d = gcd(n, m);
  L = (long long)n / (long long)d * (long long)m;
  for (int i = 0; i < n; ++i) {
    ++s[i % d][x[i] - 'a'];
  }
  long long ans = 0;
  for (int i = 0; i < m; ++i) {
    long long sum = 0;
    sum += n / d - s[i % d][y[i] - 'a'];
    ans += sum;
  }
  ans *= N * (long long)n / L;
  printf("%I64d\n", ans);
  return 0;
}
