#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m, Mod, a[N], b[N];
void Init() {
  scanf("%d %d %d", &n, &m, &Mod);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
}
long long Gcd(long long a, long long b) {
  if (!b) return a;
  return Gcd(b, a % b);
}
int t, q[N], d[N];
void Divisor_Decompose(int n) {
  d[0] = 0;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      d[++d[0]] = i;
      if (i * i != n) d[++d[0]] = n / i;
    }
  }
  sort(d + 1, d + d[0] + 1);
}
inline long long Power(long long a, long long b, long long Mod) {
  long long c = 1;
  for (; b; b >>= 1) {
    if (b & 1) (c *= a) %= Mod;
    (a *= a) %= Mod;
  }
  return c;
}
int f[N], g[N];
void Solve() {
  t = Mod - 1;
  for (int i = 1; i <= m; ++i) t = Gcd(t, b[i]);
  Divisor_Decompose(Mod - 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= d[0]; ++j)
      if (Power(a[i], d[j], Mod) == 1) {
        q[i] = (Mod - 1) / d[j];
        q[i] = Gcd(1ll * q[i] * t, Mod - 1);
        break;
      }
  }
  sort(q + 1, q + n + 1);
  int m = unique(q + 1, q + n + 1) - q - 1;
  int ans = 0;
  for (int i = d[0]; i; --i) {
    f[i] = (Mod - 1) / d[i];
    for (int j = i + 1; j <= d[0]; ++j)
      if (d[j] % d[i] == 0) f[i] -= f[j];
    if (d[i] == q[m]) {
      for (int j = i; j <= d[0]; ++j)
        if (d[j] % d[i] == 0 && !g[j]) {
          g[j] = 1;
          ans += f[j];
        }
      --m;
    }
  }
  printf("%d\n", ans);
}
int main() {
  Init();
  Solve();
  return 0;
}
