#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; map prime; void prime_factor(ll n){ prime.clear(); ll m = n; if (n % 2 == 0){ while(n % 2 == 0){ prime[2]++; n /= 2; } } for (ll i = 3; i*i <= m; i+=2){ if (n % i == 0){ while(n % i == 0){ prime[i]++; n /= i; } } } if (n != 1){ prime[n]++; } } template using pq = priority_queue, greater>; vector dijkstra(vector> &E, vector &B){ ll N = E.size(); ll from, alt, d; pq> que; vector dist(N, 1e18); vector vst(N); dist[0] = B[0]; que.push({B[0], 0}); while(!que.empty()){ tie(d, from) = que.top(); que.pop(); if (vst[from]) continue; vst[from] = 1; for (auto to : E[from]){ alt = max(d, B[to]); if (alt < dist[to]){ dist[to] = alt; que.push({dist[to], to}); } } } return dist; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* Aの素因数pごとに考える。 素因数pの指数eを考えると、LCMのGCD->MAXのMIN 1->xに行く時のeの最大値の最小値でdist(x)を定める。 p^dist(x)の積 */ ll N, M, u, v; cin >> N >> M; //素因数の集合 vector v2, A(N); vector ans(N, 1); for (int i=0; i> A[i]; prime_factor(A[i]); for (auto [p, e] : prime) v2.push_back(p); } sort(v2.begin(), v2.end()); v2.erase(unique(v2.begin(), v2.end()), v2.end()); vector> E(N); for (int i=0; i> u >> v; u--; v--; E[u].push_back(v); E[v].push_back(u); } for (auto p : v2){ vector B(N); for (int i=0; i dist = dijkstra(E, B); for (int i=0; i