```cpp #include #define LL long long #define pii pair #define mem(a, b) memset(a, b, sizeof(a)) using namespace std;
const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; const LL MOD = 998244353;
inline int read() { int s = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { f = -1; ch = getchar(); } while (isdigit(ch)) { s = (s <<1) + (s <<3) + ch - '0'; ch = getchar(); } return s * f; }
inline void write(int x) { if (x <0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); }
struct Edge { int to, next; } edge[maxn <<2];
int cnt, head[maxn], a[maxn]; int prime[maxn], num, sum; bool is[maxn], vis[maxn]; vector g[maxn]; map mp;
void init() { is[0] = is[1] = true; for (int i = 2; i <= 1e5; ++i) { if (!is[i]) prime[num++] = i; for (int j = 0; i is[i * prime[j]] = true; if (i % prime[j] == 0) break; } } }
void dfs(int now, int nm) { sum++; vis[now] = true; for (int i = head[now]; i; i = edge[i].next) { int to = edge[i].to; if (!vis[to] && a[to] % nm == 0) { dfs(to, nm); } } }
int main() { init(); int n = read(), u, v; for (int i = 1; i u = read(), v = read(); add(u, v), add(v, u); } for (int i = 1; i <= n; ++i) a[i] = read(); for (int i = 1; i <= n; ++i) { int tmp = a[i]; for (int j = 0; j if (tmp % prime[j] == 0) { g[prime[j]].push_back(i); while (tmp % prime[j] == 0) tmp /= prime[j]; } } if (tmp > 1) { if (tmp <= 1e5) g[tmp].push_back(i); else mp[tmp]++; } } int ans = 0; for (auto it : mp) ans = max(ans, it.second); for (int i = 2; i <= 1e5; ++i) { for (auto it : g[i]) { if (!vis[it]) { sum = 0; dfs(it, i); ans = max(ans, sum); } } for (auto it : g[i]) vis[it] = false; } write(ans); return 0; } ```