#include <bits/stdc++.h>
template <class T>
inline void readin(T &res) {
  static char ch;
  T flag = 1;
  while ((ch = getchar()) < '0' || ch > '9')
    if (ch == '-') flag = -1;
  res = ch - 48;
  while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - 48;
  res *= flag;
}
template <class T>
inline T abs(T a) {
  return a >= 0 ? a : -a;
}
template <class T>
inline T max(T a, T b) {
  return a >= b ? a : b;
}
template <class T>
inline T min(T a, T b) {
  return a <= b ? a : b;
}
int P, PHIP;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int mpow(int a, int b, int mod) {
  static int res;
  for (res = 1; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) res = 1ll * res * a % mod;
  return res;
}
int list[31623], tot;
void find() {
  for (int i = 1; i * i <= PHIP; i++)
    if (PHIP % i == 0) {
      list[++tot] = i;
      list[++tot] = PHIP / i;
    }
}
int n, m, B, a[10010], f[10010];
int main() {
  readin(n);
  readin(m);
  readin(P);
  PHIP = P - 1;
  find();
  std::sort(list + 1, list + tot + 1);
  for (int i = 1; i <= n; i++) readin(a[i]);
  B = PHIP;
  for (int i = 1, x; i <= m; i++) readin(x), B = gcd(B, x);
  for (int i = 1, j; i <= n; i++) {
    a[i] = mpow(a[i], B, P);
    for (j = 1; j <= tot; j++)
      if (mpow(a[i], list[j], P) == 1) {
        a[i] = PHIP / list[j];
        break;
      }
  }
  std::sort(a + 1, a + n + 1);
  n = std::unique(a + 1, a + n + 1) - a - 1;
  int ans = 0;
  for (int i = n, j; i >= 1; i--) {
    f[i] = PHIP / a[i];
    for (j = i + 1; j <= n; j++)
      if (a[j] % a[i] == 0) f[i] -= f[j];
    ans += f[i];
  }
  printf("%d\n", ans);
  return 0;
}
