# CF588-DIV2-E Kamil and Making a Stream

http://codeforces.com/contest/1230/problem/E

## 代码

#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define PB push_back
#define LL long long
#define pii pair<int,int>
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<<x<<endl;
#define FIO ios::sync_with_stdio(false);
#define ALL(x) x.begin(),x.end()
typedef long long ll;
const ll mod = 1e9+7;
const int maxn =1e5+10;
LL a[maxn];
LL ans=0;
LL dp[maxn][21],fa[maxn][21];
LL mul(LL a,LL b){return (a*b)%mod;};
vector<int> V[maxn];
void dfs(int x,int f){
fa[x][0]=x;fa[x][1]=f;
dp[x][0]=a[x];dp[x][1]=__gcd(a[x],a[f]);
for(int c:V[x])
if(c!=f) dfs(c,x);
}
void gao(int x,LL g){
LL ret=0;
int flag=0;
if(x==1) return;
for(int i=20;i>=1;i--){
if(fa[x][i]!=0&&__gcd(g,dp[x][i])==g){
gao(fa[x][i],g);
flag=1;
break;
}
}
return;
}
int main(){
FIO;
int n,x,y;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<n;i++){
cin>>x>>y;
V[x].PB(y),V[y].PB(x);
}
a[0]=mod;
dfs(1,0);
for(int i=2;i<=20;i++)
for(int j=1;j<=n;j++)
fa[j][i]=fa[fa[j][i-1]][i-1],dp[j][i]=__gcd(dp[j][i-1],dp[fa[j][i-1]][i-1]);
for(int i=1;i<=n;i++)