#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m, pr[N], cnt, w[233], ccc;
bool ip[N];
vector<int> f[233];
char s[N], t[N];
void sieve(int n) {
  memset(ip, 1, sizeof(ip));
  ip[1] = 0;
  for (int i = (2); i <= (n); ++i) {
    if (ip[i]) pr[++cnt] = i;
    for (int j = 1; j <= cnt && i * pr[j] <= n; ++j) {
      ip[i * pr[j]] = 0;
      if (i % pr[j] == 0) break;
    }
  }
  for (int i = (2); i <= (40); ++i)
    for (int j = (1); j <= (cnt); ++j)
      if (pr[j] > m && pr[j] % pr[i] == 1) f[i].push_back(pr[j]);
}
int ksm(int a, int b, int p) {
  int ans = 1;
  for (; b; b >>= 1, a = 1ll * a * a % p)
    if (b & 1) ans = 1ll * ans * a % p;
  return ans;
}
int main() {
  mt19937 rd;
  uniform_int_distribution<> g(2, 40);
  scanf("%d%d%s%s", &n, &m, s, t);
  for (int i = (0); i <= (n - 1); ++i) s[i] -= t[i];
  sieve(1e6);
  for (int x = (2); x <= (40); ++x) {
    for (int i = (0); i <= (pr[x] - 1); ++i) w[i] = 0;
    for (int i = (0); i <= (n - 1); ++i) w[i % pr[x]] += s[i];
    for (int &y : f[x]) {
      uniform_int_distribution<> gen(2, y - 1);
      int z = gen(rd), zz = 1;
      while (ksm(z, (y - 1) / pr[x], y) == 1) z = gen(rd), ++ccc;
      zz = z = ksm(z, (y - 1) / pr[x], y);
      for (int i = (1); i <= (pr[x]); ++i) {
        int gg = 0, cc = 1;
        for (int j = (0); j <= (pr[x] - 1); ++j)
          gg = (gg + 1ll * cc * (w[j] % y + y)) % y, cc = 1ll * cc * zz % y,
          ++ccc;
        if (gg == 0) return printf("%d %d\n", y, zz), 0;
        zz = 1ll * zz * z % y;
      }
    }
  }
  return 0;
}
