#include <bits/stdc++.h>
using namespace std;
int N, M, P;
int A[100005], B[100005];
int D[100005], cnt, R[100005], F[100005];
int gcd(int a, int b) {
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
void findD(int x) {
  cnt = 0;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      D[++cnt] = i;
      if (i * i != x) D[++cnt] = x / i;
    }
  }
  sort(D + 1, D + cnt + 1);
}
int powerLog(int n, int p) {
  int sol = 1;
  while (p) {
    if (p % 2 == 1) sol = (1LL * sol * n) % P;
    n = (1LL * n * n) % P;
    p /= 2;
  }
  return sol;
}
void Solve() {
  cin >> N >> M >> P;
  for (int i = 1; i <= N; i++) cin >> A[i];
  int t = P - 1;
  for (int i = 1; i <= M; i++) {
    int b;
    cin >> b;
    t = gcd(t, b);
  }
  findD(P - 1);
  int aux = (P - 1) / t;
  for (int i = 1; i <= N; i++) {
    int point = 0;
    for (int j = 1; j <= cnt; j++) {
      if (powerLog(A[i], D[j]) == 1) {
        point = D[j];
        break;
      }
    }
    R[i] = gcd((P - 1) / point, (P - 1) / t);
  }
  findD((P - 1) / t);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= cnt; j++)
      if (D[j] % R[i] == 0) F[j] = 1;
  }
  long long ans = 0;
  for (int i = 1; i <= cnt; i++) {
    if (F[i] == 0) continue;
    ans += (1LL * F[i] * aux / D[i]);
    for (int j = i + 1; j <= cnt; j++)
      if (D[j] % D[i] == 0) F[j] -= F[i];
  }
  cout << ans << "\n";
}
int main() {
  Solve();
  return 0;
}
