#include <bits/stdc++.h>
using namespace std;
const long long N = 100010;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long n, m, p, a[N], b[N], q[N], yue[N], miu[N], f[N], tot;
long long ans;
long long power(long long a, long long b, long long m) {
  long long re = 1;
  while (b) {
    if (b & 1) re = (long long)re * a % m;
    a = (long long)a * a % m;
    b >>= 1;
  }
  return re;
}
long long calc(long long x) {
  long long i, j, k, l;
  for (i = 1; i <= tot; i++)
    if (power(x, yue[i], p) == 1) return yue[i];
}
int main() {
  long long i, j, k;
  scanf("%I64d%I64d%I64d", &n, &m, &p);
  for (i = 1; i * i <= p - 1; i++) {
    if ((p - 1) % i == 0) {
      yue[++tot] = i;
      if (i * i < p - 1) yue[++tot] = (p - 1) / i;
    }
  }
  sort(yue + 1, yue + tot + 1);
  for (i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  for (i = 1, k = 0; i <= m; i++) {
    scanf("%I64d", &j);
    k = gcd(k, j);
  }
  k = gcd(k, p - 1);
  for (i = 1; i <= n; i++) {
    q[i] = calc(a[i]);
    a[i] = (p - 1) * gcd(q[i], k) / q[i];
  }
  for (i = 1; i <= tot; i++)
    for (j = 1; j <= n; j++)
      if (yue[i] % a[j] == 0) {
        f[i] = 1;
        break;
      }
  for (i = 1; i <= tot; i++) {
    ans += (f[i] - miu[i]) * ((p - 1) / yue[i]);
    for (j = i + 1; j <= tot; j++)
      if (yue[j] % yue[i] == 0) miu[j] += (f[i] - miu[i]);
    miu[i] += (f[i] - miu[i]);
  }
  cout << ans << endl;
  return 0;
}
