#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, m, p, x;
  cin >> n >> m >> p;
  long long int p1 = 0, p2 = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    if (gcd(p, x) == 1) p1 = i;
  }
  for (long long int i = 0; i < m; i++) {
    cin >> x;
    if (gcd(p, x) == 1) p2 = i;
  }
  cout << p1 + p2;
}
