#include <bits/stdc++.h>
using namespace std;
void io_in_data() {
  freopen("data.in", "r", stdin);
  freopen("data1.out", "w", stdout);
}
const int MAXN = 1000007;
long long cnt[1][MAXN][26];
char s1[MAXN], s2[MAXN];
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  long long n, m;
  while (cin >> n >> m) {
    scanf("%s%s", s1 + 1, s2 + 1);
    memset(cnt, 0, sizeof(cnt));
    long long l1 = strlen(s1 + 1);
    long long l2 = strlen(s2 + 1);
    int i, j;
    long long g = gcd(l1, l2);
    long long lcm = l1 * l2 / g;
    long long ans = 0;
    for (i = 1; s1[i] != '\0'; i++) cnt[0][i % g][s1[i] - 'a'] += 1;
    for (i = 1; s2[i] != '\0'; i++) ans += cnt[0][i % g][s2[i] - 'a'];
    cout << n * l1 - n * l1 / lcm * ans << endl;
  }
  return 0;
}
