#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (a == 0) ? b : gcd(b % a, a); }
char x[1000010];
char y[1000010];
int main() {
  long long n, m;
  cin >> n >> m >> x >> y;
  long long len1 = strlen(x);
  long long len2 = strlen(y);
  long long g = gcd(len1, len2);
  long long ans = 0;
  for (long long i = 0; i < g; i++) {
    long long freqx[26];
    long long freqy[26];
    for (int rr = 0; rr < 26; rr++) {
      freqx[rr] = freqy[rr] = 0;
    }
    for (long long j = 0; j < len1 / g; j++) {
      freqx[x[i + j * g] - 'a']++;
    }
    for (long long j = 0; j < len2 / g; j++) {
      freqy[y[i + j * g] - 'a']++;
    }
    for (int rr = 0; rr < 26; rr++) {
      ans += freqx[rr] * freqy[rr];
    }
  }
  long long num = len1 / g * len2;
  cout << len1 * n - ans * (n * g / len2) << endl;
}
