#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const int maxn = 1e4, max_num = 1e5;
int fpm(long long b, int e, const int &m) {
  long long t = 1;
  for (; e; e >>= 1, (b *= b) %= m)
    if (e & 1) (t *= b) %= m;
  return t;
}
int gcd(int first, int second) {
  while (second) second ^= first ^= second ^= first %= second;
  return first;
}
int n, m, p;
int a[maxn + 5];
int ans = 0;
int main() {
  scanf("%d%d%d", &n, &m, &p);
  vector<int> all;
  for (int i = 1; i * i <= p - 1; ++i)
    if (!((p - 1) % i)) {
      all.push_back(i);
      if (i * i != p - 1) all.push_back((p - 1) / i);
    }
  sort((all).begin(), (all).end());
  for (int i = (0), _end_ = (n); i != _end_; ++i) scanf("%d", a + i);
  int yyt = p - 1;
  for (int i = (0), _end_ = (m); i != _end_; ++i) {
    static int first;
    scanf("%d", &first);
    yyt = gcd(yyt, first);
  }
  for (int i = (0), _end_ = (n); i != _end_; ++i)
    for (int j = (0), _end_ = ((int((all).size()))); j != _end_; ++j)
      if (fpm(a[i], (long long)all[j] * yyt % (p - 1), p) == 1) {
        a[i] = (p - 1) / all[j];
        break;
      }
  static int dp[max_num + 5];
  reverse((all).begin(), (all).end());
  for (int i = (0), _end_ = ((int((all).size()))); i != _end_; ++i) {
    bool flag = 0;
    for (int j = (0), _end_ = (n); j != _end_; ++j)
      if (!(all[i] % a[j])) {
        flag = 1;
        break;
      }
    if (!flag) continue;
    dp[i] = (p - 1) / all[i];
    for (int j = (0), _end_ = (i); j != _end_; ++j)
      if (!(all[j] % all[i])) dp[i] -= dp[j];
    ans += dp[i];
  }
  printf("%d\n", ans);
  return 0;
}
