#include <bits/stdc++.h>
const long long N = 1000001;
long long n, m, add[N][27], l1, l2, gc, ans;
char s1[N], s2[N];
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
void makeadd() {
  for (long long i = 0; i < gc; i++)
    for (long long j = i; j < l1; j += gc) ++add[i][s1[j] - 'a'];
}
void makeans() {
  for (long long i = 0; i < l2; i++)
    for (long long j = 0; j < 26; j++)
      if (s2[i] - 'a' != j) ans += add[i % gc][j];
}
int main() {
  scanf("%I64d%I64d", &n, &m);
  scanf("%s", s1);
  scanf("%s", s2);
  l1 = strlen(s1);
  l2 = strlen(s2);
  gc = gcd(l1, l2);
  makeadd();
  makeans();
  ans *= l1 * n / (l1 * l2 / gc);
  printf("%I64d", ans);
}
