#include <bits/stdc++.h>
using namespace std;
char a[1000002], b[1000002];
long long n, m, r, le;
long long la, lb, g, l, ans;
int dpa[1000002][26];
int dpb[1000002][26];
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  while (scanf("%I64d %I64d", &n, &m) != EOF) {
    scanf("%s", a);
    scanf("%s", b);
    la = strlen(a);
    lb = strlen(b);
    g = la > lb ? gcd(la, lb) : gcd(lb, la);
    l = la * lb / g;
    memset(dpa, 0, sizeof(dpa));
    memset(dpb, 0, sizeof(dpb));
    for (int i = 0; i < la; i++) {
      dpa[i % g][a[i] - 'a']++;
    }
    for (int i = 0; i < lb; i++) {
      dpb[i % g][b[i] - 'a']++;
    }
    ans = 0;
    for (int i = 0; i < g; i++) {
      for (int j = 0; j < 26; j++) {
        ans += (long long)dpa[i][j] * (long long)dpb[i][j];
      }
    }
    ans = n * la / l * ans;
    ans = n * la - ans;
    printf("%I64d\n", ans);
  }
  return 0;
}
