#include <bits/stdc++.h>
using namespace std;
int n, m;
int A[10000 + 10], B[100000 + 10], p;
int gcd(int a, int b) {
  while (b) {
    int t = a % b;
    a = b;
    b = t;
  }
  return a;
}
int fastPow(int b, int pow) {
  int ans = 1;
  b %= p;
  while (pow) {
    if (pow & 1) ans = (int)((long long)ans * b % p);
    pow >>= 1;
    b = (int)((long long)b * b % p);
  }
  return ans;
}
int di[500010], dn;
int val[10000 + 10];
map<pair<int, long long>, long long> f;
long long dfs(int cur, long long sum) {
  if (sum > p - 1) return 0;
  if (f.find(make_pair(cur, sum)) != f.end()) return f[make_pair(cur, sum)];
  long long ans = (p - 2) / sum + 1;
  if (cur >= 0 && sum <= p - 1)
    for (int j = cur; j >= 0; j--)
      ans -= dfs(j - 1, sum / gcd((int)sum, val[j]) * val[j]);
  f[make_pair(cur, sum)] = ans;
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i < n; i++) scanf("%d", A + i);
  int g = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d", B + i);
    g = gcd(g, B[i]);
  }
  dn = 0;
  for (int i = 1; i * i <= p - 1; i++) {
    if (i * i == p - 1)
      di[dn++] = i;
    else if ((p - 1) % i == 0) {
      di[dn++] = i;
      di[dn++] = (p - 1) / i;
    }
  }
  sort(di, di + dn);
  for (int i = 0; i < n; i++) {
    int tmp = fastPow(A[i], g);
    int j;
    for (j = 0; fastPow(tmp, di[j]) != 1; j++)
      ;
    val[i] = (p - 1) / di[j];
  }
  sort(val, val + n);
  n = unique(val, val + n) - val;
  printf(
      "%I64d"
      "\n",
      p - 1 - dfs(n - 1, 1));
  return 0;
}
