#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> num;
string x, y;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void input() {
  cin >> n >> m;
  cin >> x >> y;
}
void solve() {
  long long d = gcd(x.size(), y.size());
  long long ans = 0;
  vector<long long> bukvx('z' - 'a' + 1, 0);
  vector<long long> bukvy('z' - 'a' + 1, 0);
  for (long long i = 0; i < d; ++i) {
    bukvx = vector<long long>('z' - 'a' + 1, 0);
    bukvy = vector<long long>('z' - 'a' + 1, 0);
    for (long long j = i; j < x.size(); j += d) {
      bukvx[x[j] - 'a']++;
    }
    for (long long j = i; j < y.size(); j += d) {
      bukvy[y[j] - 'a']++;
    }
    for (long long j = 0; j < bukvx.size(); ++j) {
      long long t = 1;
      long long a = y.size();
      long long u;
      long long now;
      now = bukvx[j] * (y.size() / d - bukvy[j]) * (n / (y.size() / d));
      ans += now;
    }
  }
  cout << ans << endl;
}
int main() {
  input();
  solve();
  return 0;
}
