#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, c, d; int n, m; while (cin >> n >> m) { int count = 0; cin >> a >> b; int x = gcd(n, m); int tempn = n / x; int tempm = m / x; while (tempn--) { c += a; } while (tempm--) { d += b; } for (int i = 0;i < c.length();i++) { if (c[i] != d[i]) { count++; } } printf("%d\n", count*x); } } |
Double click to view unformatted code.