#include //#include //priority_queue #definePIIpair<int,int> #definelllonglongusingnamespace std;constint INF &#61;0x3f3f3f3f; constint N &#61;200100; int a[N]; vector <int> head[N]; set <int> vis[N]; int f[N][3]; int np[N]; int mnp[N]; voidsi() {for(int i &#61;2; i <&#61;1e5&#43;5; i&#43;&#43;){if(!np[i]){for(int j &#61; i ; j <&#61;1e5&#43;5; j &#43;&#61; i ){np[j]&#61;1; mnp[j]&#61; i ;}}} } voiddfs(int x ,int p ) {vis[x].insert(p);int cnt &#61;0;while( a[x]% p &#61;&#61;0)a[x]/&#61;p,cnt&#43;&#43;;int sum1 &#61;0,sum0 &#61;0;for(int i &#61;0; i < head[x].size(); i&#43;&#43;){int sk &#61; head[x][i];if(!vis[sk].count(p)&& a[sk]% p &#61;&#61;0){dfs(sk,p); sum0 &#43;&#61;min(f[sk][0],f[sk][1]); sum1 &#43;&#61; f[sk][1];}}f[x][0]&#61; sum1 ; f[x][1]&#61; sum0 &#43; cnt ; } voidsolve() {si();int n ;cin >> n ;for(int i &#61;1; i <&#61; n ; i&#43;&#43;)cin >> a[i];for(int i &#61;1; i < n ; i&#43;&#43;){int t1 , t2 ;cin >> t1 >> t2 ; head[t1].push_back(t2); head[t2].push_back(t1);}int ans &#61;0;for(int i &#61;1; i <&#61; n ; i&#43;&#43;){while( a[i]!&#61;1){int p &#61; mnp[a[i]];if(!vis[i].count(p)){dfs(i,p); ans &#43;&#61;min(f[i][1],f[i][0]);}}}cout << ans <<"\n"; } intmain() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);solve();return0; }