#include #include #include #include using lint = long long; std::map count(int n) { std::vector xs(n); for (auto& x : xs) std::cin >> x; std::map ret; for (int b = 0; b < (1 << n); ++b) { lint g = 0; for (int i = 0; i < n; ++i) { if ((b >> i) & 1) g = std::gcd(g, xs[i]); } if (!ret.count(g)) ret[g] = 0; ++ret[g]; } return ret; } void solve() { int n; std::cin >> n; auto fore = count(n / 2), back = count(n - n / 2); lint ans = 0; for (auto p : fore) { for (auto q : back) { if (std::gcd(p.first, q.first) == 1) { ans += p.second * q.second; } } } std::cout << ans << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }