func_code_string: #include <bits/stdc++.h>   using namespace std;   const int iinf = 0x3f3f3f3f;   const long long linf = 0x3f3f3f3f3f3f3f3f;   const int N = 1e4, M = 1e5;   int n, m, p, a[N], b[M];   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   int mypow(int a, int first = p - 2, int res = 1) {     for (; first; first >>= 1, a = 1ll * a * a % p)       (first & 1) && (res = 1ll * res * a % p);     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n >> m >> p;     int phi = p - 1, g = phi;     for (int i(0); i < (n); ++i) cin >> a[i];     for (int i(0); i < (m); ++i) cin >> b[i], g = gcd(g, b[i]);     vector<int> c;     for (int d = 1; d * d <= phi; ++d)       if (phi % d == 0)         c.push_back(d), d *d < phi ? c.push_back(phi / d) : void();     sort(c.begin(), c.end());     vector<int> mb;     for (int i(0); i < (n); ++i) {       int mn_c = -1;       for (int &u : c)         if (mypow(a[i], 1ll * g * u % phi) == 1) {           mb.push_back(phi / u);           break;         }     }     sort(mb.begin(), mb.end());     mb.erase(unique(mb.begin(), mb.end()), mb.end());     vector<int> f(int((mb).size()), 0);     int ns = 0;     for (int i((int((mb).size())) - 1); i >= 0; --i) {       f[i] = phi / mb[i];       for (int j = i + 1; j < int((mb).size()); ++j)         if (mb[j] % mb[i] == 0) f[i] -= f[j];       ns += f[i];     }     cout << ns <<   n ;     return 0;   }   