#include <bits/stdc++.h>
using namespace std;
int a[100001], b[100001], c[100001][2], d[100001];
int p, n, m, t, fip, ans, top;
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
int calc(int x, int y, int MOD) {
  static int s;
  s = 1;
  while (y) {
    if (y & 1) s = (long long)s * x % MOD;
    x = (long long)x * x % MOD, y >>= 1;
  }
  return s;
}
bool jian(int x) {
  for (int i = 1; i <= n; i++)
    if (!(x % b[i])) return 1;
  return 0;
}
int fi(int x) {
  static int s;
  s = x;
  for (int i = 2; i * i <= x; i++)
    if (!(x % i)) {
      while (!(x % i)) x /= i;
      s = s / i * (i - 1);
    }
  if (x > 1) s = s / x * (x - 1);
  return s;
}
void divide(int x) {
  top = 0;
  for (int i = 2; i * i <= x; i++)
    if (!(x % i)) {
      c[++top][0] = i, c[top][1] = 0;
      while (!(x % i)) x /= i, c[top][1]++;
    }
  if (x != 1) c[++top][0] = x, c[top][1] = 1;
}
void dfs(int x, int y) {
  if (x > top) return;
  for (int i = c[x][1]; i >= 0; i--) {
    dfs(x + 1, y);
    y *= c[x][0];
    if (i) d[++d[0]] = y;
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &t);
  while (--m) {
    int x;
    scanf("%d", &x);
    t = gcd(t, x);
  }
  fip = p - 1;
  divide(fip);
  d[0] = d[1] = 1;
  dfs(1, 1);
  for (int i = 1; i <= n; i++) {
    int di;
    for (int j = 1; j <= d[0]; j++)
      if (calc(a[i], d[j], p) == 1) {
        di = d[j];
        break;
      }
    b[i] = gcd((long long)fip / di * t, fip);
  }
  ans = 0;
  for (int i = 1; i <= d[0]; i++)
    if (jian(d[i])) ans += fi(fip / d[i]);
  printf("%d\n", ans);
  return 0;
}
