#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long int;
using vi = vector<int>;
using pii = pair<int, int>;
using graph = vector<vector<pair<pair<int, int>, pair<int, int> > > >;
const int inf = 1e+9;
ll GCD(ll a, ll b) {
  if (a < b) swap(a, b);
  return b ? GCD(b, a % b) : a;
}
ll n, m, xsz, ysz, _n, _m;
vector<vector<ll> > y_set;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  string x, y;
  cin >> x >> y;
  xsz = x.size();
  ysz = y.size();
  ll gcd = GCD(xsz, ysz);
  _n = ysz / gcd, _m = xsz / gcd;
  y_set.resize(gcd, {});
  for (int i = 0; i < gcd; i++) y_set[i].resize(26, 0);
  for (int i = 0; i < xsz; i++) {
    ll pos = i % gcd;
    y_set[pos][x[i] - 'a']++;
  }
  ll ans = 0;
  for (int i = 0; i < ysz; i++) {
    ll pos = i % gcd;
    for (int j = 0; j < 26; j++) {
      if (y[i] != j + 'a') {
        ans += y_set[pos][j];
      }
    }
  }
  ans *= (m / _m);
  cout << ans;
  return 0;
}
