#include <bits/stdc++.h>   using namespace std;   inline long long gcd(long long n1, long long n2) {     return n2 == 0 ? abs(n1) : gcd(n2, n1 % n2);   }   inline long long lcm(long long n1, long long n2) {     return n1 == 0 || n2 == 0 ? 0 : abs(n1 * (n2 / gcd(n1, n2)));   }   const int INF = 1000000000;   const int MAXN = 1000006;   int mat[MAXN][30];   int mark[MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     while (cin >> n >> m) {       string s1, s2;       cin >> s1 >> s2;       long long t1 = (int)s1.size(), t2 = (int)s2.size();       long long x = gcd(t1, t2);       memset(mark, 0, sizeof mark);       memset(mat, 0, sizeof mat);       for (int i = 0; i < t1; ++i) mat[i % x][s1[i] -  a ]++;       long long res = 0LL;       for (int i = 0; i < t2; ++i) res += (t1 / x) - mat[i % x][s2[i] -  a ];       res *= (t1 * n) / lcm(t1, t2);       cout << res << endl;     }   }   