#include <bits/stdc++.h>
using namespace std;
int n, m, P, a[10010], b[100010], Phi, D[1010], q[10010], r[10010], f[1010];
void read(int &x) {
  char ch = getchar();
  int mark = 1;
  for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar())
    ;
  if (ch == '-') mark = -1, ch = getchar();
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
  x *= mark;
}
int gcd(int a, int b) { return (b) ? gcd(b, a % b) : a; }
int Mul(long long x, int y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % P;
    x = x * x % P;
    y >>= 1;
  }
  return ans;
}
int main() {
  read(n);
  read(m);
  read(P);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 1; i <= m; i++) read(b[i]);
  Phi = P - 1;
  int t = Phi, cnt = 0;
  for (int i = 1; i <= m; i++) t = gcd(t, b[i]);
  for (int i = 1; i * i <= Phi; i++)
    if (Phi % i == 0) {
      D[++cnt] = i;
      if (i * i != Phi) D[++cnt] = Phi / i;
    }
  sort(D + 1, D + cnt + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= cnt; j++)
      if (Mul(a[i], D[j]) == 1) {
        r[i] = Phi / D[j];
        break;
      }
  }
  for (int i = 1; i <= n; i++) q[i] = gcd(Phi, (long long)r[i] * t % Phi);
  sort(q + 1, q + n + 1);
  n = unique(q + 1, q + n + 1) - (q + 1);
  int ans = 0;
  for (int i = n; i; i--) {
    f[i] += Phi / q[i];
    for (int j = 1; j < i; j++)
      if (q[i] % q[j] == 0) f[j] -= f[i];
    ans += f[i];
  }
  printf("%d\n", ans);
  return 0;
}
