#include <bits/stdc++.h>
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline unsigned int getuint() {
  char w = getchar();
  while (w < '0' || '9' < w) w = getchar();
  unsigned int ans = 0;
  for (; '0' <= w && w <= '9'; w = getchar()) ans = ans * 10 + w - '0';
  return ans;
}
int mod;
inline long long qpow(long long x, int y) {
  long long ans = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) ans = ans * x % mod;
  return ans;
}
int a[100005], b[100005];
std::vector<int> factor, f;
int main() {
  int n = getuint(), m = getuint();
  mod = getuint();
  for (int i = 1; i <= n; i++) a[i] = getuint();
  int t = mod - 1;
  for (int i = 1; i <= m; i++) t = gcd(t, b[i] = getuint());
  for (int i = 1; i * i < mod; i++)
    if ((mod - 1) % i == 0) {
      factor.push_back(i);
      if (i * i < mod - 1) factor.push_back((mod - 1) / i);
    }
  std::sort(factor.begin(), factor.end());
  f.resize(factor.size());
  for (int i = 1; i <= n; i++) {
    a[i] = qpow(a[i], t);
    for (int j = (int)factor.size() - 1;; j--)
      if (qpow(a[i], (mod - 1) / factor[j]) == 1) {
        f[j] = (mod - 1) / factor[j];
        break;
      }
  }
  long long ans = 0;
  for (int i = (int)f.size() - 1; ~i; ans += f[i--])
    if (f[i])
      for (int j = (int)f.size() - 1; j > i; j--)
        if (factor[j] % factor[i] == 0) f[i] -= f[j];
  printf("%I64d\n", ans);
  return 0;
}
