/* -*- coding: utf-8 -*- * * 2497.cc: No.2497 GCD of LCMs - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 250; const int MOD = 998244353; const int MAX_P = 32000; const int INF = 1 << 30; /* typedef */ using ll = long long; using vb = vector; using vi = vector; using pii = pair; using vpii = vector; /* global variables */ vb primes; vi pnums; int as[MAX_N], ups[MAX_N * 15]; vi nbrs[MAX_N]; int es[MAX_N], ds[MAX_N], gs[MAX_N]; /* subroutines */ int gen_primes(int maxp) { primes.assign(maxp + 1, true); primes[0] = primes[1] = false; int p; for (p = 2; p * p <= maxp; p++) if (primes[p]) { pnums.push_back(p); for (int q = p * p; q <= maxp; q += p) primes[q] = false; } for (; p <= maxp; p++) if (primes[p]) pnums.push_back(p); return (int)pnums.size(); } bool prime_decomp(int n, vpii& pds) { pds.clear(); for (auto pi: pnums) { if (pi * pi > n) { if (n > 1) pds.push_back(pii(n, 1)); return true; } if (n % pi == 0) { int fi = 0; while (n % pi == 0) n /= pi, fi++; pds.push_back(pii(pi, fi)); } } return false; } int powmod(int a, int b) { int p = 1; while (b > 0) { if (b & 1) p = (ll)p * a % MOD; a = (ll)a * a % MOD; b >>= 1; } return p; } /* main */ int main() { gen_primes(MAX_P); int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; nbrs[u].push_back(v); nbrs[v].push_back(u); } int k = 0; for (int i = 0; i < n; i++) { vpii pds; prime_decomp(as[i], pds); for (auto [p, d]: pds) ups[k++] = p; } sort(ups, ups + k); k = unique(ups, ups + k) - ups; //printf(" ups=%d\n", k); fill(gs, gs + n, 1); for (int i = 0; i < k; i++) { int p = ups[i]; for (int i = 0; i < n; i++) { es[i] = 0; for (int ai = as[i]; ai % p == 0; ai /= p) es[i]++; } fill(ds, ds + n, INF); ds[0] = es[0]; priority_queue q; q.push({-es[0], 0}); while (! q.empty()) { auto [ud, u] = q.top(); q.pop(); ud = -ud; if (ds[u] != ud) continue; for (auto v: nbrs[u]) { int vd = max(ud, es[v]); if (ds[v] > vd) { ds[v] = vd; q.push({-vd, v}); } } } for (int i = 0; i < n; i++) gs[i] = (ll)gs[i] * powmod(p, ds[i]) % MOD; } for (int i = 0; i < n; i++) printf("%d\n", gs[i]); return 0; }