#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int expo(long long a, long long b, long long m) {
  long long r = 1;
  while (b) {
    if (b & 1) r = (r * a) % m;
    a = (a * a) % m;
    b >>= 1LL;
  }
  return r;
}
int ls[20];
int ts[10100];
int g[10100];
bool eh[10100];
int main() {
  int n, m, p;
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 0; i < n; i++) scanf("%d", g + i);
  int gg;
  scanf("%d", &gg);
  for (int i = 0; i < m - 1; i++) {
    int v;
    scanf("%d", &v);
    gg = gcd(gg, v);
  }
  for (int i = 0; i < n; i++) g[i] = expo(g[i], gg, p);
  int q = 0, pp = p - 1;
  for (int i = 2; i < pp + 1; i++) {
    if (i * i > pp) break;
    if (pp % i == 0) {
      ls[q++] = i;
      while (pp % i == 0) pp /= i;
    }
  }
  if (pp != 1) ls[q++] = pp;
  for (int i = 0; i < n; i++) {
    ts[i] = p - 1;
    bool eh = true;
    while (eh) {
      eh = false;
      for (int j = 0; j < q; j++) {
        if (ts[i] % ls[j] == 0 && expo(g[i], ts[i] / ls[j], p) == 1)
          ts[i] /= ls[j], eh = true;
      }
    }
  }
  sort(ts, ts + n);
  int qts = unique(ts, ts + n) - ts;
  for (int i = 0; i < qts; i++) eh[i] = true;
  for (int i = 0; i < qts; i++)
    for (int j = 0; j < i; j++) {
      if (ts[i] % ts[j] == 0) eh[j] = false;
    }
  int w = 0;
  for (int i = 0; i < qts; i++) {
    if (eh[i]) ts[w++] = ts[i];
  }
  int lim = 1 << w;
  int s = 0;
  for (int i = 1; i < lim; i++) {
    int z = -1, cnt = 0;
    for (int j = 0; j < w; j++) {
      if ((i & (1 << j))) {
        if (z == -1)
          z = ts[j];
        else
          z = gcd(z, ts[j]);
        cnt++;
      }
    }
    if (cnt & 1)
      s += z;
    else
      s -= z;
  }
  printf("%d\n", s);
  return 0;
}
