#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (!b ? a : gcd(b, a % b)); }
long long lcm(const long long &a, const long long &b) {
  return a / gcd(a, b) * b;
}
const int N_MAX = 1e4;
long long arr[N_MAX];
long long pwr(long long a, long long p, const long long &mod) {
  long long ret = 1;
  while (p) {
    if (p & 1) ret = (ret * a) % mod;
    p >>= 1;
    a = (a * a) % mod;
  }
  return ret;
}
vector<long long> fac;
long long f[N_MAX];
int main() {
  int n, m;
  long long p;
  scanf("%d%d%I64d", &n, &m, &p);
  for (int i = 0; i < n; i++) scanf("%I64d", arr + i);
  long long unit;
  scanf("%I64d", &unit);
  for (int i = 1; i < m; i++) {
    long long ipt;
    scanf("%I64d", &ipt);
    unit = gcd(unit, ipt);
  }
  for (long long i = 1; i * i <= (p - 1); i++) {
    if ((p - 1) % i == 0) {
      fac.push_back(i);
      if (i * i != p - 1) fac.push_back((p - 1) / i);
    }
  }
  sort((fac).begin(), (fac).end());
  for (int i = 0; i < n; i++) {
    arr[i] = pwr(arr[i], unit, p);
    for (long long x : fac) {
      if (pwr(arr[i], x, p) == 1) {
        arr[i] = x;
        break;
      }
    }
  }
  sort(arr, arr + n);
  n = unique(arr, arr + n) - arr;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++)
      if (arr[i] % arr[j] == 0) arr[j] = arr[i];
  }
  sort(arr, arr + n);
  n = unique(arr, arr + n) - arr;
  long long ans = 0;
  for (int i = 1; i < (1 << n); i++) {
    int cnt = 0;
    long long tmp = 1;
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        cnt++;
        tmp = lcm(tmp, (p - 1) / arr[j]);
      }
    }
    if ((cnt & 1) == 0) tmp *= (-1);
    ans += (p - 1) / tmp;
  }
  printf("%I64d\n", ans);
  return 0;
}
