#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long 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 n, m, p, tot, ans;
int a[100005], b[100005], q[100005];
int d[100005], f[100005];
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int qpow(long long a, int b) {
  long long ans = 1;
  for (int i = b; i; i >>= 1, a = a * a % p)
    if (i & 1) ans = ans * a % p;
  return ans;
}
int main() {
  n = read();
  m = read();
  p = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  int t = p - 1;
  for (int i = 1; i <= m; i++) b[i] = read();
  for (int i = 1; i <= n; i++) t = gcd(t, b[i]);
  for (int i = 1; i * i <= p - 1; i++)
    if ((p - 1) % i == 0) {
      d[++tot] = i;
      if (i * i != p - 1) d[++tot] = (p - 1) / i;
    }
  sort(d + 1, d + tot + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = qpow(a[i], t);
    for (int j = 1; j <= tot; j++)
      if (qpow(a[i], d[j]) == 1) {
        q[i] = (p - 1) / d[j];
        break;
      }
  }
  sort(q + 1, q + n + 1);
  n = unique(q + 1, q + n + 1) - q - 1;
  for (int i = n; i; i--) {
    f[i] = (p - 1) / q[i];
    for (int j = i + 1; j <= n; j++)
      if (q[j] % q[i] == 0) f[i] -= f[j];
    ans += f[i];
  }
  printf("%d\n", ans);
  return 0;
}
