#include<iostream> #include<string> using namespace std; int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a%b); } int main() { string a, b; int n, m; while (cin >> n >> m) { getchar(); int count = 0; getline(cin, a); getline(cin, b); int x = gcd(n, m); int tempn = n / x; int tempm = m / x; string c, d; while (tempn--) { c += a; } while (tempm--) { d += b; } for (int i = 0;i < c.length();i++) { if (c[i] != d[i]) { count++; } } cout << count * x << endl; } } |
Double click to view unformatted code.