#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
int n, m, p;
int a[MaxN], b;
int dv[MaxN], tot;
int freq[MaxN], ans[MaxN], res;
int gcd(int a, int b) {
  while (a && b)
    if (a >= b)
      a %= b;
    else
      b %= a;
  return a + b;
}
int mypow(long long b, int n) {
  long long res = 1;
  for (; n; n >>= 1) {
    if (n & 1) res = res * b % p;
    b = b * b % p;
  }
  return res;
}
int main(void) {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  b = p - 1;
  for (int i = 0, t; i < m; ++i) {
    scanf("%d", &t);
    b = gcd(b, t);
  }
  for (int i = 1; i * i <= p - 1; ++i)
    if ((p - 1) % i == 0) {
      dv[tot++] = i;
      if (i * i != p - 1) dv[tot++] = (p - 1) / i;
    }
  sort(dv, dv + tot);
  for (int i = 0; i < n; ++i) {
    a[i] = mypow(a[i], b);
    for (int j = 0; j < tot; ++j) {
      if (mypow(a[i], dv[j]) == 1) {
        freq[i] = (p - 1) / dv[j];
        break;
      }
    }
  }
  sort(freq, freq + n);
  n = unique(freq, freq + n) - freq;
  reverse(freq, freq + n);
  for (int i = 0; i < n; ++i) {
    ans[i] = (p - 1) / freq[i];
    for (int j = 0; j < i; ++j)
      if (freq[j] % freq[i] == 0) ans[i] -= ans[j];
    res += ans[i];
  }
  printf("%d\n", res);
  return 0;
}
