#include <bits/stdc++.h>
using namespace std;
long long t, n, m, p, mb, ans, a[100005], b[100005];
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long pow(long long a, long long b, long long p) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return ans;
}
void work() {
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  long long p1 = p - 1;
  vector<long long> di;
  for (long long i = 1; i * i <= p1; i++) {
    if (p1 % i) continue;
    di.push_back(i);
    if (i * i != p1) di.push_back(p1 / i);
  }
  sort(di.begin(), di.end());
  mb = (p - 1), ans = 0;
  for (int i = 1; i <= m; i++) {
    mb = gcd(mb, b[i]);
  }
  for (int i = 1; i <= n; i++) a[i] = pow(a[i], mb, p);
  vector<bool> vis(di.size());
  for (int i = 1; i <= n; i++) {
    for (int j = di.size() - 1; j >= 0; j--) {
      if (pow(a[i], p1 / di[j], p) == 1) {
        vis[j] = true;
        break;
      }
    }
  }
  for (int i = 0; i < di.size(); i++) {
    if (vis[i]) {
      for (int j = i + 1; j < di.size(); j++) {
        if (di[j] % di[i] == 0) vis[j] = true;
      }
    }
  }
  vector<long long> rc(di.size());
  for (int i = di.size() - 1; i >= 0; i--) {
    rc[i] = p1 / di[i];
    for (int j = i + 1; j < di.size(); j++)
      if (di[j] % di[i] == 0) rc[i] -= rc[j];
    if (vis[i]) ans += rc[i];
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n >> m >> p) {
    work();
  }
  return 0;
}
