#include <bits/stdc++.h>
using namespace std;
long long N, M, P, ans, G;
long long pr[100005], tot, son[100005], S;
long long cnt[100005], num[100005], len;
long long vis[100005], A[100005], q[100005];
long long dp[100005];
map<long long, long long> rk;
void Find_Prime() {
  long long i, j, to = sqrt(P);
  for (i = 2; i <= to; i++) {
    if (!vis[i]) pr[++tot] = i;
    for (j = i * 2; j <= to; j += i) vis[j] = 1;
  }
}
void Break(long long x) {
  long long i, now = x;
  for (i = 1; i <= tot; i++)
    while (now % pr[i] == 0) num[++len] = pr[i], now /= pr[i];
  if (now != 1) num[++len] = now;
  sort(num + 1, num + 1 + len);
  for (i = 1, now = 0; i <= len; i++)
    if (num[i] != num[i - 1])
      num[++now] = num[i], cnt[now] = 1;
    else
      cnt[now]++;
  len = now;
}
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long ksm(long long x, long long t) {
  long long tmp = 1;
  for (tmp; t; t >>= 1, x = x * x % P)
    if (t & 1) tmp = x * tmp % P;
  return tmp;
}
long long Ask(long long x) {
  long long i, j, now = (P - 1);
  for (i = 1; i <= len; i++)
    for (j = 0; j < cnt[i] && ksm(x, now / num[i]) == 1; j++, now /= num[i])
      ;
  return now;
}
void Dfs(long long x, long long now) {
  if (x > len) {
    son[++S] = now;
    return;
  }
  for (long long i = 0; i <= cnt[x]; i++, now *= num[x]) Dfs(x + 1, now);
}
int main() {
  long long i, j, tmp;
  scanf("%I64d %I64d %I64d", &N, &M, &P);
  Find_Prime(), Break(P - 1);
  for (i = 1; i <= N; i++) scanf("%I64d", &A[i]);
  for (i = 1, G = P - 1; i <= M; i++) scanf("%I64d", &j), G = gcd(G, j);
  for (i = 1; i <= N; i++) A[i] = ksm(A[i], G), q[i] = Ask(A[i]);
  Dfs(1, 1), sort(son + 1, son + 1 + S);
  for (i = 1; i <= S; i++) rk[son[i]] = i;
  dp[rk[q[1]]] = 1;
  for (i = 2; i <= N; i++) {
    for (j = 1; j <= S; j++) {
      tmp = gcd(q[i], son[j]);
      dp[rk[tmp]] -= dp[rk[son[j]]];
    }
    dp[rk[q[i]]]++;
  }
  for (i = 1; i <= S; i++) ans += dp[i] * son[i];
  printf("%I64d\n", abs(ans));
  return 0;
}
