#include <bits/stdc++.h>
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
using namespace std;
const int MX = 10005, INF = 1000010000;
const long long int LINF = 1000000000000000000ll;
const double eps = 1e-10;
const int di[] = {-1, 0, 1, 0}, dj[] = {0, -1, 0, 1};
long long int gcd(long long int x, long long int y) {
  return y ? gcd(y, x % y) : x;
}
vector<int> ps;
vector<bool> pf;
void sieve(int mx) {
  pf.resize(mx + 1);
  fill(pf.begin(), pf.end(), true);
  pf[0] = pf[1] = false;
  for (long long int i = 2; i <= mx; i++) {
    if (!pf[i]) continue;
    ps.push_back(i);
    for (long long int j = i * i; j <= mx; j += i) pf[j] = false;
  }
}
int n, m, p;
int a[MX], b;
long long int ex(long long int x, long long int y) {
  if (!y) return 1;
  long long int r = ex(x, y >> 1);
  return r * r % p * (y & 1 ? x : 1) % p;
}
vector<int> d;
vector<pair<int, int> > e;
map<int, int> mp;
int q;
void dfs(int i, int x, int y) {
  if (i == e.size()) {
    mp[x] = y;
    return;
  }
  int z = 1, mx;
  for (int j = 0; j < e[i].second; ++j) z *= e[i].first;
  mx = z;
  int sum = 0;
  for (int j = 0; j < e[i].second + 1; ++j) {
    int now = mx / z - sum;
    dfs(i + 1, x * z, y * now);
    sum += now;
    z /= e[i].first;
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int j = 0; j < m; ++j) {
    int nb;
    scanf("%d", &nb);
    b = gcd(b, nb);
  }
  m = q = p - 1;
  sieve(100005);
  for (int x : ps) {
    int c = 0;
    while (m % x == 0) {
      m /= x;
      ++c;
    }
    if (c) e.push_back({x, c});
  }
  if (m != 1) e.push_back({m, 1});
  for (int i = 1; i * i <= q; ++i) {
    d.push_back(i);
    if (i * i != q) d.push_back(q / i);
  }
  sort(d.begin(), d.end());
  set<int> s;
  for (int i = 0; i < n; ++i) {
    int z = q;
    a[i] = ex(a[i], b);
    for (auto x : e) {
      for (int j = 0; j < x.second; ++j) {
        int now = z / x.first;
        if (ex(a[i], now) != 1) break;
        z = now;
      }
    }
    s.insert(q / z);
  }
  dfs(0, 1, 1);
  int ans = 0;
  for (int x : d) {
    bool ok = false;
    for (int y : s) {
      if (x % y == 0) ok = true;
    }
    if (ok) ans += mp[x];
  }
  cout << ans << endl;
  return 0;
}
