func_code_string: #include <bits/stdc++.h>   using namespace std;   long long cyc[1000006][27], n, m;   long long done[1000006];   string a, b;   int main() {     cin >> n >> m;     cin >> a >> b;     int s1 = a.size();     int s2 = b.size();     long long tot = s1 * n;     memset(cyc, 0, sizeof(cyc));     memset(done, 0, sizeof(done));     long long ans = 0;     for (int i = 0; i < s1; i++) {       int st = i % s2;       if (!done[st]) {         int H[27];         memset(H, 0, sizeof(H));         H[b[st] -  a ]++;         done[st] = 1;         int pos = 1;         int en = (st + s1) % s2;         while (en != st) {           pos++;           H[b[en] -  a ]++;           done[en] = pos;           en = (en + s1) % s2;         }         done[st] = pos;         for (int k = 0; k < 26; k++) cyc[st][k] = H[k];         en = (st + s1) % s2;         while (en != st) {           for (int k = 0; k < 26; k++) cyc[en][k] = H[k];           done[en] = pos;           en = (en + s1) % s2;         }       }       ans += (cyc[st][a[i] -  a ] * ((tot) / (s1 * done[st])));     }     cout << tot - ans << endl;     return 0;   }   