#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
char a[maxn], b[maxn];
int cnt[50];
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int main() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  scanf("%s", a);
  scanf("%s", b);
  long long len1 = strlen(a);
  long long len2 = strlen(b);
  long long g = gcd(len1, len2);
  long long lc = lcm(len1, len2);
  long long lena = len1 / g, lenb = len2 / g;
  long long ans = 0;
  for (long long i = 0; i < g; i++) {
    memset(cnt, 0, sizeof(cnt));
    for (long long j = 0; j < lena; j++) {
      cnt[a[g * j + i] - 'a']++;
    }
    for (long long j = 0; j < lenb; j++) {
      ans += cnt[b[g * j + i] - 'a'];
    }
  }
  ans *= len1 * n / lc;
  ans = len1 * n - ans;
  printf("%lld\n", ans);
  return 0;
}
