#include <bits/stdc++.h>
using namespace std;
int p, n, m, a[10050], Div[10050], st, ans, b, Ans[10050];
inline int Read() {
  int x = 0;
  char y;
  do y = getchar();
  while (y < '0' || y > '9');
  do x = x * 10 + y - '0', y = getchar();
  while (y >= '0' && y <= '9');
  return x;
}
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
long long Quick_Power(long long x, long long y) {
  long long z = 1;
  while (y) {
    if (y & 1) z = z * x % p;
    x = x * x % p;
    y >>= 1;
  }
  return z;
}
int main() {
  n = Read();
  m = Read();
  p = Read();
  b = p - 1;
  for (int i = 1; i <= n; i++) a[i] = Read();
  for (int i = 1; i <= m; i++) b = gcd(b, Read());
  for (int i = 1; i * i < p; i++)
    if ((p - 1) % i == 0) {
      Div[++st] = i;
      if (i * i != p - 1) Div[++st] = (p - 1) / i;
    }
  sort(Div + 1, Div + st + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = Quick_Power(a[i], b);
    for (int j = 1; j <= st; j++)
      if (Quick_Power(a[i], Div[j]) == 1) {
        Ans[j] = true;
        break;
      }
  }
  for (int i = 1; i <= st; i++)
    if (Ans[i]) {
      Ans[i] = Div[i];
      for (int j = 1; j < i; j++)
        if (Div[i] % Div[j] == 0) Ans[i] -= Ans[j];
      ans += Ans[i];
    }
  cout << ans << endl;
  return 0;
}
