#include #include namespace nono { namespace internal { constexpr bool is_prime(unsigned long long n) { for (unsigned long long i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } } // namespace internal template class Modint { public: constexpr Modint(unsigned long long value = 0): value_(value % MOD) {} constexpr Modint pow(long long exp) const { Modint result(1); Modint base(*this); while (exp > 0) { if (exp & 1) { result *= base; } base *= base; exp >>= 1; } return result; } constexpr Modint inv() const { return pow(MOD - 2); } void set(unsigned long long value) { if (value >= MOD) value %= MOD; value_ = value; } unsigned long long get() const { return value_; } constexpr Modint& operator+=(const Modint other) { this->value_ += other.value_; if (this->value_ >= MOD) this->value_ -= MOD; return *this; } constexpr Modint& operator-=(const Modint other) { this->value_ += MOD - other.value_; if (this->value_ >= MOD) this->value_ -= MOD; return *this; } constexpr Modint& operator*=(const Modint other) { this->value_ *= other.value_; if (this->value_ >= MOD) this->value_ %= MOD; return *this; } constexpr Modint& operator/=(const Modint other) { this->value_ *= other.inv(); if (this->value_ >= MOD) this->value_ %= MOD; return *this; } constexpr friend Modint operator+(const Modint lhs, const Modint rhs) { return Modint(lhs) += rhs; } constexpr friend Modint operator-(const Modint lhs, const Modint rhs) { return Modint(lhs) -= rhs; } constexpr friend Modint operator*(const Modint lhs, const Modint rhs) { return Modint(lhs) *= rhs; } constexpr friend Modint operator/(const Modint lhs, const Modint rhs) { return Modint(lhs) /= rhs; } friend std::istream& operator>>(std::istream& stream, Modint& mint) { unsigned long long value; stream >> value; mint.set(value); return stream; } friend std::ostream& operator<<(std::ostream& stream, Modint mint) { stream << mint.get(); return stream; } private: unsigned long long value_; }; } // namespace nono namespace nono { std::vector> factorize(long long n) { std::vector> result; for (long long i = 2; i * i <= n; i++) { int count = 0; while (n % i == 0) { count++; n /= i; } if (count > 0) { result.emplace_back(i, count); } } if (n != 1) { result.emplace_back(n, 1); } return result; } void solve() { using Mint = Modint<998244353>; int n, m; std::cin >> n >> m; std::vector a(n); std::set s; for (int i = 0; i < n; i++) { std::cin >> a[i]; for (auto [k, v]: factorize(a[i])) { s.insert(k); } } std::vector graph(n, std::vector()); for (int i = 0; i < m; i++) { int u, v; std::cin >> u >> v; u--; v--; graph[u].push_back(v); graph[v].push_back(u); } std::vector ans(n, 1); for (auto k: s) { std::vector max(n, 1e9); using P = std::pair; std::priority_queue, std::greater

> pq; max[0] = 0; { long long temp = a[0]; while (temp % k == 0) { max[0]++; temp /= k; } } pq.emplace(0, max[0]); while (!pq.empty()) { auto [u, c] = pq.top(); pq.pop(); if (max[u] != c) continue; for (auto w: graph[u]) { int g = 0; long long temp = a[w]; while (temp % k == 0) { g++; temp /= k; } g = std::max(max[u], g); if (max[w] > g) { max[w] = g; pq.emplace(w, g); } } } for (int i = 0; i < n; i++) { ans[i] *= Mint(k).pow(max[i]); } } for (int i = 0; i < n; i++) { std::cout << ans[i] << std::endl; } } } // namespace nono int main() { std::cin.tie(0)->sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); int t = 1; while (t--) nono::solve(); }