#include <bits/stdc++.h>
using namespace std;
const int M = (int)1e4 + 5, N = (int)1e5 + 5;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int n, m, p;
int a[M], b[N];
vector<int> fac, dp;
int fast(int a, int b) {
  int re = 1;
  while (b) {
    if (b & 1) re = (long long)re * a % p;
    a = (long long)a * a % p, b >>= 1;
  }
  return re;
}
int main() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  for (int i = 1; i * i < p; i++)
    if ((p - 1) % i == 0) {
      fac.push_back(i);
      if ((p - 1) / i != i) fac.push_back((p - 1) / i);
    }
  sort(fac.begin(), fac.end());
  int gd = p - 1;
  for (int i = 1; i <= m; i++) gd = gcd(gd, b[i]);
  dp.resize(fac.size());
  for (int i = 1, ab, t; i <= n; i++) {
    ab = fast(a[i], gd);
    t = fac.size() - 1;
    while (fast(ab, (p - 1) / fac[t]) != 1) t--;
    dp[t] = (p - 1) / fac[t];
  }
  long long ans = 0;
  for (int i = dp.size() - 1; i >= 0; i--)
    if (dp[i]) {
      for (int j = dp.size() - 1; j > i; j--)
        if (fac[j] % fac[i] == 0) dp[i] -= dp[j];
      ans += dp[i];
    }
  cout << ans << endl;
  return 0;
}
