#include <bits/stdc++.h>
long long int A, B, C, ans;
int a[1000000][26], b[1000000][26], qsb[1000000];
using namespace std;
string s1, s2;
int main() {
  scanf("%I64d%I64d", &A, &B);
  cin >> s1 >> s2;
  int n1 = s1.size(), n2 = s2.size();
  int c = max(n1, n2), c1 = min(n1, n2);
  while (c1 != 0) {
    c %= c1;
    swap(c, c1);
  }
  for (int i = 0; i < n1; i++) a[i % c][s1[i] - 'a']++;
  for (int i = 0; i < n2; i++) {
    b[i % c][s2[i] - 'a']++;
    qsb[i % c]++;
  }
  for (int i = 0; i < c; i++)
    for (int j = 0; j <= 25; j++)
      ans += (long long int)a[i][j] * (qsb[i] - (long long int)b[i][j]);
  C = A * (long long int)c / (long long int)n2;
  printf("%I64d", ans * C);
}
