假设p=nY,q=mY,则X=nmY且n,m 互质
用map把X中的质数和指数存进去,如果Y中有X没有的质数或指数更大,那么答案为0,如果Y与X相同,答案为1,剩下的一种情况的答案就是2^(X/Y后剩余的质数种类的数量)
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5+5;
const int mod = 998244353;
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
inline void solve() {
int n; cin >> n;
vector<int>a(n);
map<int, int>mpa;
vector<int>b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
mpa[a[i]] = b[i];
}
int m; cin >> m;
vector<int>c(m);
vector<int>d(m);
for (int i = 0; i < m; i++) {
cin >> c[i];
}
bool fg = 0;
for (int i = 0; i < m; i++) {
cin >> d[i];
if (mpa[c[i]] < d[i]) {
fg = 1;
}
else
mpa[c[i]] -= d[i];
}
if (m > n||fg) {
cout << 0 << '\n';
return;
}
int ans = 1;
int cnt = 0;
for (auto i : mpa) {
if (i.second != 0)
cnt++;
}
while (cnt) {
ans *= 2;
ans %= mod;
cnt--;
}
cout << ans << '\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
std::cout.tie(0);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}