#include <bits/stdc++.h>
using namespace std;
const int iinf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e4, M = 1e5, d_N = 4e4;
int n, m, p, a[N], b[M], c[N];
int d_n, pd[d_N], f[d_N];
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
int mypow(int a, int first = p - 2, int res = 1) {
  for (; first; first >>= 1, a = 1ll * a * a % p)
    (first & 1) && (res = 1ll * res * a % p);
  return res;
}
int main() {
  cin >> n >> m >> p;
  int phi = p - 1, g = phi;
  for (int i(0); i < (n); ++i) cin >> a[i];
  for (int i(0); i < (m); ++i) cin >> b[i], g = gcd(g, b[i]);
  for (int d = 1; d * d <= phi; ++d)
    if (phi % d == 0) pd[d_n++] = d, d * d < phi ? pd[d_n++] = phi / d : 0;
  sort(pd, pd + d_n);
  for (int i(0); i < (n); ++i) {
    int t = mypow(a[i], g);
    for (int j(0); j < (d_n); ++j)
      if (mypow(t, pd[j]) == 1) {
        c[i] = phi / pd[j];
        break;
      }
  }
  int ns = 0;
  for (int i((d_n)-1); i >= 0; --i) {
    bool mark = false;
    for (int j(0); j < (n); ++j)
      if (pd[i] % c[j] == 0) {
        mark = true;
        break;
      }
    if (mark) {
      f[i] = phi / pd[i];
      for (int j = i + 1; j < d_n; ++j)
        if (pd[j] % pd[i] == 0) f[i] -= f[j];
      ns += f[i];
    }
  }
  cout << ns << '\n';
  return 0;
}
