#include <bits/stdc++.h>
using namespace std;
const int mxn = 100010;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int ksm(int a, int k, int p) {
  int res = 1;
  while (k) {
    if (k & 1) res = (long long)res * a % p;
    a = (long long)a * a % p;
    k >>= 1;
  }
  return res;
}
int gcd(int a, int b) { return (!b) ? a : gcd(b, a % b); }
int n, m, P;
int a[mxn], b[mxn];
int pr[mxn], cnt = 0;
int q[mxn], f[mxn];
int main() {
  int i, j;
  n = read();
  m = read();
  P = read();
  for (i = 1; i <= n; i++) a[i] = read();
  int tmp = P - 1, ph = P - 1;
  for (i = 1; i <= m; i++) b[i] = read(), tmp = gcd(tmp, b[i]);
  for (i = 1; i * i <= ph; i++)
    if (ph % i == 0) {
      pr[++cnt] = i;
      if (i * i != ph) pr[++cnt] = ph / i;
    }
  sort(pr + 1, pr + cnt + 1);
  for (i = 1; i <= n; i++) {
    a[i] = ksm(a[i], tmp, P);
    for (j = 1; j <= cnt; j++) {
      if (ksm(a[i], pr[j], P) == 1) {
        q[i] = ph / pr[j];
        break;
      }
    }
  }
  sort(q + 1, q + n + 1);
  int ed = unique(q + 1, q + n + 1) - q - 1;
  long long ans = 0;
  q[++ed] = P - 1;
  for (i = ed; i; i--) {
    f[i] = ph / q[i];
    for (j = i + 1; j <= ed; j++)
      if (q[j] % q[i] == 0) f[i] -= f[j];
    ans += f[i];
  }
  printf("%I64d\n", ans);
  return 0;
}
