#include <bits/stdc++.h>
using namespace std;
namespace star {
const int maxn = 1e6 + 10, N = 1e6;
int n, m, p[maxn], a[maxn], tot;
bool mark[maxn];
char s1[maxn], s2[maxn];
inline int fpow(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;
}
mt19937 rand(time(0));
inline void work() {
  scanf("%d%d%s%s", &n, &m, s1, s2);
  for (int i = 0; i < n; i++) s1[i] -= s2[i];
  for (int i = 2; i <= N; i++) {
    if (!mark[i]) p[++tot] = i;
    for (int j = 1; j <= tot and i * p[j] <= N; j++) {
      mark[i * p[j]] = true;
      if (i % p[j] == 0) break;
    }
  }
  for (int d = 3; d <= N; d++)
    if (!mark[d]) {
      for (int i = 0; i < n; i++) a[i % d] += s1[i];
      for (int P = m / d * d + d + 1; P <= N; P += d)
        if (!mark[P]) {
          uniform_int_distribution<int> rd(2, P - 2);
          int r;
          while (fpow(r = rd(rand), (P - 1) / d, P) == 1)
            ;
          r = fpow(r, (P - 1) / d, P);
          for (int y = r, i = 1; i <= d; i++, y = 1ll * y * r % P) {
            int ans = 0, z = 1;
            for (int j = 0; j < d; j++)
              ans = (ans + 1ll * a[j] * z) % P, z = 1ll * z * y % P;
            if (!ans) return (void)printf("%d %d\n", P, y);
          }
        }
      for (int i = 0; i < d; i++) a[i] = 0;
    }
}
}  // namespace star
signed main() {
  star::work();
  return 0;
}
