#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
const int maxn = 10005, maxm = 100005;
int n, m, p, T, phip, ans, a[maxn];
bool vis[maxn];
long long _pow(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % p;
    y >>= 1, x = x * x % p;
  }
  return ret % p;
}
int gcd(int a, int b) {
  if (a < b) swap(a, b);
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}
int cur[maxn], tot = 0, phi[maxn];
int main() {
  n = read(), m = read(), p = read();
  phip = p - 1;
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= m; i++) T = gcd(read(), T);
  for (int i = 1; i * i <= phip; i++)
    if (phip % i == 0) {
      cur[++tot] = i;
      if (i * i != phip) cur[++tot] = phip / i;
    }
  sort(cur + 1, cur + 1 + tot);
  for (int i = 1; i <= n; i++) {
    int t = _pow(a[i], T);
    for (int j = 1; j <= tot; j++)
      if (_pow(t, cur[j]) == 1) {
        vis[tot - j + 1] = true;
        break;
      }
  }
  for (int i = 1; i <= tot; i++)
    if (vis[i])
      for (int j = i + 1; j <= tot; j++)
        if (cur[j] % cur[i] == 0) vis[j] = 1;
  for (int i = 1; i <= tot; i++) {
    phi[i] = cur[i];
    for (int j = 1; j < i; j++)
      if (cur[i] % cur[j] == 0) phi[i] -= phi[j];
    if (vis[tot - i + 1]) ans += phi[i];
  }
  printf("%d\n", ans);
  return 0;
}
