#include <bits/stdc++.h>
using namespace std;
const int MaxN = 10000;
const int GL = 500000;
const int MaxM = 100000;
inline int gcd(int a, int b) {
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int pr;
inline int modpow(const int &a, const int &n) {
  int res = 1;
  int t = a;
  for (int i = n; i >= 1; i >>= 1) {
    if (i & 1) res = (long long)res * t % pr;
    t = (long long)t * t % pr;
  }
  return res;
}
int main() {
  int n, m;
  vector<int> divisor;
  cin >> n >> m >> pr;
  static int a[MaxN + 1], b[MaxM + 1];
  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 <= pr - 1; i++)
    if ((pr - 1) % i == 0) {
      divisor.push_back(i);
      if ((pr - 1) / i != i) divisor.push_back((pr - 1) / i);
    }
  sort(divisor.begin(), divisor.end());
  int gcdB = pr - 1;
  for (int i = 1; i <= m; i++) gcdB = gcd(gcdB, b[i]);
  vector<int> f;
  f.resize(divisor.size());
  for (int i = 1; i <= n; i++) {
    int ag = modpow(a[i], gcdB);
    int k = (int)divisor.size() - 1;
    while (modpow(ag, (pr - 1) / divisor[k]) != 1) k--;
    f[k] = (pr - 1) / divisor[k];
  }
  long long res = 0;
  for (int i = (int)f.size() - 1; i >= 0; i--) {
    if (f[i] == 0) continue;
    for (int j = (int)f.size() - 1; j > i; j--)
      if (divisor[j] % divisor[i] == 0) f[i] -= f[j];
    res += f[i];
  }
  cout << res << endl;
  return 0;
}
