#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m, p;
int a[N], b[N];
int dr[N], dn, r[N], f[N];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int fpm(int a, int b, int p) {
  int w = 1;
  for (; b; b >>= 1, a = 1LL * a * a % p)
    if (b & 1) w = 1LL * w * a % p;
  return w;
}
int main() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  int tb = p - 1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d", b + i);
    tb = gcd(tb, b[i]);
  }
  for (int x = 1; 1LL * x * x <= p - 1; ++x)
    if ((p - 1) % x == 0) {
      dr[++dn] = x;
      if (x != (p - 1) / x) {
        dr[++dn] = (p - 1) / x;
      }
    }
  sort(dr + 1, dr + dn + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= dn; ++j)
      if (fpm(a[i], dr[j], p) == 1) {
        r[i] = gcd(1LL * (p - 1) / dr[j] * tb % (p - 1), p - 1);
        break;
      }
  sort(r + 1, r + n + 1);
  int nn = unique(r + 1, r + n + 1) - r - 1;
  int tot = 0;
  for (int i = nn; i >= 1; --i) {
    f[i] = (p - 1) / r[i];
    for (int j = i + 1; j <= nn; ++j)
      if (r[j] % r[i] == 0) {
        f[i] -= f[j];
      }
    tot += f[i];
  }
  printf("%d\n", tot);
}
