#include <bits/stdc++.h>
using namespace std;
const int N(10010), M(100010);
int n, m, p;
int a[N];
int b[M];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int mul(int a, int b) { return (long long)a * b % p; }
int pow(int a, int b) {
  if (b == 0) return 1;
  int t = pow(a, b / 2);
  t = mul(t, t);
  return b % 2 ? mul(t, a) : t;
}
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] % (p - 1));
  }
  for (int i = 0; i != n; ++i) a[i] = pow(a[i], g);
  vector<int> fac;
  for (int 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());
  vector<bool> bo(fac.size());
  for (int i = 0; i != n; ++i)
    for (int j = fac.size() - 1; j != -1; --j)
      if (pow(a[i], (p - 1) / fac[j]) == 1) {
        bo[j] = true;
        break;
      }
  for (int i = 0; i != fac.size(); ++i)
    if (bo[i])
      for (int j = i + 1; j != fac.size(); ++j)
        if (fac[j] % fac[i] == 0) bo[j] = true;
  int ans = 0;
  vector<int> cnt(fac.size());
  for (int i = fac.size() - 1; i != -1; --i) {
    cnt[i] = (p - 1) / fac[i];
    for (int j = i + 1; j != fac.size(); ++j)
      if (fac[j] % fac[i] == 0) cnt[i] -= cnt[j];
    if (bo[i]) ans += cnt[i];
  }
  printf("%d\n", ans);
  return 0;
}
