#include <bits/stdc++.h>
using namespace std;
int n, m, p, d[100010], cnt, a[100010], dp[100010], ans;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long calc(long long a, long long b, long long mod) {
  long long ans = 1, t = a;
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * t % mod;
    t = t * t % mod;
  }
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int GCD = p - 1;
  for (int i = 1; i <= m; i++) {
    int x;
    scanf("%d", &x);
    GCD = gcd(GCD, x);
  }
  for (int i = 1; i * i < p; i++)
    if ((p - 1) % i == 0) {
      d[++cnt] = i;
      if (i * i != p - 1) d[++cnt] = (p - 1) / i;
    }
  sort(d + 1, d + cnt + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= cnt; j++)
      if (calc(a[i], GCD * d[j], p) == 1) {
        a[i] = (p - 1) / d[j];
        break;
      }
  sort(a + 1, a + n + 1);
  m = unique(a + 1, a + n + 1) - a - 1;
  reverse(a + 1, a + m + 1);
  for (int i = 1; i <= m; i++) {
    dp[i] = (p - 1) / a[i];
    for (int j = 1; j < i; j++)
      if (a[j] % a[i] == 0) dp[i] -= dp[j];
    ans += dp[i];
  }
  printf("%d\n", ans);
  return 0;
}
