#include <iostream>

using namespace std;

#ifndef ONLINE_JUDGE
  #include <fstream>
  #define cin fin
  #define cout fout
  ifstream fin("test.in");
  ofstream fout("test.out");
#endif

int n, nr, a[101], s, pas, j = 1;
void suma() {
    s = 0;
    for (int i = 1; i <= n; i++)
        s = s + a[i];
}
int main()
{
    cin >> nr;
    for (int i = 1; i <= nr; i++) {
        pas = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            if (a[i] == 0) {
                a[i] = a[i] + 1;
                pas++;
            }
        }
        suma();
        if (s == 0)
            do {
                a[j] = a[j] + 1;
                j++;
                pas++;
                suma();
           } while (s < 0);
        cout << pas << endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

#ifndef ONLINE_JUDGE
  #include <fstream>
  #define cin fin
  #define cout fout
  ifstream fin("test.in");
  ofstream fout("test.out");
#endif

int n, nr, a[101], p, s, pas, j = 1;;
void suma() {
    s = 0;
    for (int i = 1; i <= n; i++)
        s = s + a[i];
}
void produs() {
    p = 1;
    for (int i = 1; i <= n; i++)
        p = p * a[i];
}
int main()
{
    cin >> nr;
    for (int i = 1; i <= nr; i++) {
        pas = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            if (a[i] == 0) {
                a[i] = a[i] + 1;
                pas++;
            }
            suma();
            produs();
        }
        if (s == 0)
            do {
                a[j] = a[j] + 1;
                j++;
                pas++;
                suma();
           } while (s < 0);
        cout << pas << endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

#ifndef ONLINE_JUDGE
  #include <fstream>
  #define cin fin
  #define cout fout
  ifstream fin("test.in");
  ofstream fout("test.out");
#endif

int n, nr, a[101], s, pas, j = 1;

int main()
{
    cin >> nr;
    for (int i = 1; i <= nr; i++) {
        s = 0;
        pas = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            if (a[i] == 0) {
                a[i] = a[i] + 1;
                pas++;
            }
            s = s + a[i];
        }
        if (s == 0)
            do {
                a[j] = a[j] + 1;
                pas++;
                s = 0;
                for (int i = 1; i <= n; i++) {
                    s = s + a[i];
                }
           } while (s < 0);
        cout << pas << endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

#ifndef ONLINE_JUDGE
  #include <fstream>
  #define cin fin
  #define cout fout
  ifstream fin("test.in");
  ofstream fout("test.out");
#endif

int n, nr, a[101], p, s, pas, j = 1;
void suma() {
    s = 0;
    for (int i = 1; i <= n; i++)
        s = s + a[i];
}
void produs() {
    p = 1;
    for (int i = 1; i <= n; i++)
        p = p * a[i];
}
int main()
{
    cin >> nr;
    for (int i = 1; i <= nr; i++) {
        pas = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            if (a[i] == 0) {
                a[i] = a[i] + 1;
                pas++;
            }
            suma();
            produs();
        }
        if (s == 0)
            do {
                a[j] = a[j] + 1;
                j++;
                pas++;
                suma();
           } while (s < 0);
        cout << pas << endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

#ifndef ONLINE_JUDGE
  #include <fstream>
  #define cin fin
  #define cout fout
  ifstream fin("test.in");
  ofstream fout("test.out");
#endif

int n, nr, a[101], s, pas, j = 1;
void suma() {
    s = 0;
    for (int i = 1; i <= n; i++)
        s = s + a[i];
}
int main()
{
    cin >> nr;
    for (int i = 1; i <= nr; i++) {
        pas = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            if (a[i] == 0) {
                a[i] = a[i] + 1;
                pas++;
            }
            suma();
        }
        if (s == 0)
            do {
                a[j] = a[j] + 1;
                j++;
                pas++;
                suma();
           } while (s < 0);
        cout << pas << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
int ar[100];
int solve(int lol[])
{
    int pro=1,sum=0;
    for(int i=0;i<n;i++)
    {
        pro*=lol[i];
        sum+=lol[i];
    }

  //  cout<<pro<<"   "<<sum<<endl;
    if(pro!=0&&sum!=0)return 1;
    int x;
    int yy=1e9;
    for(int i=0;i<n;i++)
    {
        lol[i]++;
        yy=min(yy,solve(lol)+1);
        lol--;
        x=lol[i];
        if(i<n-1)
        {
            lol[i]=lol[i+1];
            yy=min(yy,solve(lol)+1);
        }
        lol[i]=x;
    }
    return yy;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int plusans=0;
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
            if(ar[i]==0)
            {
                ar[i]++;
                plusans++;
            }
        }
        cout<<solve(ar)-1+plusans<<endl;
       // cout<<"done"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,ans=0;
        cin>>n;
        int ar[n];
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
            if(ar[i]==0)
            {
                ans++;
                ar[i]++;
            }
        }
        for(int i=0;i<n;i++)
        {
            int pro=1,sum=0;
            for(int j=0;j<n;j++)
            {
                if(ar[j]==0)
                {
                    ans++;
                    ar[j]++;
                }
                pro*=ar[j];
                sum+=ar[j];
            }
            if(pro!=0&&sum!=0)
            {
                cout<<ans<<endl;
                break;
            }
            else
            {
                int ind;
                int maxi=-100000;
                for(int i=0;i<n;i++)
                {
                    if(ar[i]>maxi)
                    {
                        ind =i;
                        maxi=ar[i];
                    }
                }
                ar[ind]++;
                ans++;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,ans=0;
        cin>>n;
        int ar[n];
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
            if(ar[i]==0)
            {
                ans++;
                ar[i]++;
            }
        }
        for(int i=0;i<n;i++)
        {
            int pro=1,sum=0;
            for(int j=0;j<n;j++)
            {
                if(ar[j]==0)
                {
                    ans++;
                    ar[j]++;
                }
                pro*=ar[j];
                sum+=ar[j];
            }
            if(pro!=0&&sum!=0)
            {
                cout<<ans<<endl;
                break;
            }
            else
            {
                ar[0]++;
                ans++;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,ans=0;
        cin>>n;
        int ar[n];
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
            if(ar[i]==0)
            {
                ans++;
                ar[i]++;
            }
        }
        for(int i=0;i<n;i++)
        {
            int pro=1,sum=0;
            for(int j=0;j<n;j++)
            {
                pro*=ar[j];
                sum+=ar[j];
            }
            if(pro!=0&&sum!=0)
            {
                cout<<ans<<endl;
                break;
            }
            else
            {
                ar[0]++;
                ans++;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int n,plusans=0;
int ar[100];
int solve(int lol[])
{
    int pro=1,sum=0;
    for(int i=0;i<n;i++)
    {
        if(lol[i]==0)
        {
            lol[i]++;
            plusans++;
        }
        pro*=lol[i];
        sum+=lol[i];
    }
   // cout<<pro<<"   "<<sum<<endl;

  //  cout<<pro<<"   "<<sum<<endl;
    if(pro!=0&&sum!=0)
    {
       // cout<<"we did it"<<endl;
        return 1;

    }
    int x;
    int yy=1e9;
    for(int i=0;i<n;i++)
    {
        if(lol[i]+1==0)continue;
        lol[i]++;
       // cout<<yy<<"  ";
        yy=min(yy,solve(lol)+1);
        //lol--;
        lol[i]--;
        x=lol[i];
        if(i<n-1)
        {
            lol[i]=lol[i+1];
            yy=min(yy,solve(lol)+1);
        }
        lol[i]=x;
    }
    return yy;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        plusans=0;
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
            //if(ar[i]==0)
            //{
              //  ar[i]++;
            //}
        }
        cout<<solve(ar)-1+plusans<<endl;
       // cout<<"done"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int n;
int ar[100];
int solve(int lol[])
{
    int pro=1,sum=0;
    for(int i=0;i<n;i++)
    {
        pro*=lol[i];
        sum+=lol[i];
    }

  //  cout<<pro<<"   "<<sum<<endl;
    if(pro!=0&&sum!=0)return 1;
    int x;
    int yy=1e9;
    for(int i=0;i<n;i++)
    {
        lol[i]++;
        yy=min(yy,solve(lol)+1);
        lol--;
        /*x=lol[i];
        if(i<n-1)
        {
            lol[i]=lol[i+1];
            yy=min(yy,solve(lol)+1);
        }
        lol[i]=x;*/
    }
    return yy;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int plusans=0;
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
            if(ar[i]==0)
            {
                ar[i]++;
                plusans++;
            }
        }
        cout<<solve(ar)-1+plusans<<endl;
       // cout<<"done"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int n,plusans=0;
int ar[100];
int solve(int lol[])
{
    int pro=1,sum=0;
    for(int i=0;i<n;i++)
    {
        if(lol[i]==0)
        {
            lol[i]++;
            plusans++;
        }
        pro*=lol[i];
        sum+=lol[i];
    }
   // cout<<pro<<"   "<<sum<<endl;

  //  cout<<pro<<"   "<<sum<<endl;
    if(pro!=0&&sum!=0)
    {
       // cout<<"we did it"<<endl;
        return 1;

    }
    int x,y;
    int yy=1e9;
    for(int i=0;i<n;i++)
    {
        if(lol[i]+1==0)continue;
        lol[i]++;
       // cout<<yy<<"  ";
        yy=min(yy,solve(lol)+1);
        //lol--;
        lol[i]--;
        x=lol[i];
       // y=lol[i+1];
        if(i<n-1)
        {
            lol[i]=lol[i]+1;
           // lol[i+1]=x;
            yy=min(yy,solve(lol)+1);
        }
        lol[i]=x;
      //  lol[i+1]=y;
    }
    return yy;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        plusans=0;
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
            //if(ar[i]==0)
            //{
              //  ar[i]++;
            //}
        }
        cout<<solve(ar)-1+plusans<<endl;
       // cout<<"done"<<endl;
    }
}


#include<iostream>
using namespace std;
int a[100000];
int main()
{
	int t,i,j,m,n;
	cin>>t;
	while(t--)
	{
		int o=0,kum=1,sum=0;
		cin>>n;
		for(i=1;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]==0)o++;
			sum+=a[i];
			kum*=a[i];
		}
		if(sum==0&&kum==0)
		{
			cout<<o<<endl;
		}
		else if(sum==0&&kum!=0)
		{
			cout<<1<<endl;
		}
		else if(sum!=0&&kum==0)
		{
			cout<<o<<endl;
		}
		else if(sum!=0&&kum!=0)
		{
			cout<<0<<endl;
		}
	}
	return 0;
 }


#include<iostream>
using namespace std;
int a[100000];
int main()
{
	int t,i,j,m,n;
	cin>>t;
	while(t--)
	{
		int o=0,kum=1,sum=0;
		cin>>n;
		for(i=1;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]==0)o++;
			sum+=a[i];
		}
		if(sum==0&&o>0)
		{
			cout<<o<<endl;
		}
		else if(sum==0&&o==0)
		{
			cout<<1<<endl;
		}
		else if(sum!=0&&o>0)
		{
			if(sum+o==0)cout<<o+1<<endl;
			else cout<<o<<endl;
		}
		else if(sum!=0&&o==0)
		{
			cout<<0<<endl;
		}
	}
	return 0;
 }


#include<iostream>
using namespace std;
int a[100000];
int main()
{
	int t,i,j,m,n;
	cin>>t;
	while(t--)
	{
		int o=0,kum=1,sum=0;
		cin>>n;
		for(i=1;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]==0)o++;
			sum+=a[i];
			kum*=a[i];
		}
		if(sum==0&&kum==0)
		{
			cout<<o<<endl;
		}
		else if(sum==0&&kum!=0)
		{
			cout<<1<<endl;
		}
		else if(sum!=0&&kum==0)
		{
			if(sum+o==0)cout<<o+1<<endl;
			else cout<<o<<endl;
		}
		else if(sum!=0&&kum!=0)
		{
			cout<<0<<endl;
		}
	}
	return 0;
 }


#include <iostream>

using namespace std;

int main()
{
    int n, t;
    cin >> t;

    while (t--) {
        cin >> n;
        int a[n];
        int sum = 0, has1 = 0;
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            int x = 0;
            cin >> x;
            if (!x) {
                x = 1;
                ++has1;
                ans += 1;
            }
            if (x != -1)
                ++has1;
            sum += x;
        }
        if (!sum)
            if (has1)
                cout << ++ans << endl;
            else
                cout << ans + 2 << endl;
        else
            cout << ans << endl;

    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, t;
    cin >> t;

    while (t--) {
        cin>>n;
        int arr[n],sum=0,count=0;

        for(int i=0;i<n;i++)
        {
            cin>>arr[i];

            if(arr[i]==0)
                count++;
                sum+=arr[i];

        }

        sum+=count;
        if(sum==0)
            count++;

        cout<<count<<endl;

    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, t;
    cin >> t;

    while (t--) {
        cin >> n;
        int sum = 0;
        int ans = 0;
        int count_zeros=0;
        for (int i = 0; i < n; ++i) {
            int x = 0;
            cin >> x;
            if (!x) {
                ++count_zeros;
            } else
                sum += x;
        }
        sum += count_zeros;
        ans += count_zeros;
        if (!sum)
            cout << ans + 1 << endl;
        else
            cout << ans << endl;

    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <set>
#include <sstream>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define MAXX 100005
#define SIS std::ios::sync_with_stdio(false)
#define ll long long
#define INF 0x3f3f3f3f
//#include<bits/stdc++.h>
using namespace std;
//const int MAX =100;
const int mod=1e9+7;
/*const double PI=3.14159265359;
const double esp=1e-5;
//int mp[MAXX];
int  a[200005],b[100005],c[100005];
int n,m,d,x,cnt=0,k;
int num[10005];
int N,M,L;
struct node{
   int v,len,w;
   int next;
}E[2*10010];
int p[1010],eid;
void init()
{
    memset(p,-1,sizeof(p));
    eid=0;
}
void inser(int u,int v,int len)
{
    E[eid].v=v;
    E[eid].len=len;
    E[eid].next=p[u];
    p[u]=eid++;
}
int dis[1010];*/
//bool vis[1010];
ll pow_mod(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res=res*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return res%mod;
}
int n,m;
int a[1010];
int ans;
int main(){
  SIS;
  int t;
  cin>>t;
  while(t--)
  {
       cin>>n;

  int cnt=0;
     ans=0;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
      ans+=a[i];
      if(a[i]==0)
        cnt++;
  }
  if(cnt==0&&ans<0||cnt==0&&ans>0)
  {
      cout<<0<<endl;
  }
  else if(cnt==0&&ans==0)
  {
      cout<<1<<endl;
  }
  else if(cnt!=0&&ans<0)
  {
      if(cnt==abs(ans))
         cout<<cnt+1<<endl;
      else
        cout<<cnt<<endl;

  }
  else if(cnt!=0&&ans==0)
  {
      cout<<cnt<<endl;
  }
  else if(cnt!=0&&ans>0)
  {
      cout<<cnt<<endl;
  }

  }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <set>
#include <sstream>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define MAXX 100005
#define SIS std::ios::sync_with_stdio(false)
#define ll long long
#define INF 0x3f3f3f3f
//#include<bits/stdc++.h>
using namespace std;
//const int MAX =100;
const int mod=1e9+7;
/*const double PI=3.14159265359;
const double esp=1e-5;
//int mp[MAXX];
int  a[200005],b[100005],c[100005];
int n,m,d,x,cnt=0,k;
int num[10005];
int N,M,L;
struct node{
   int v,len,w;
   int next;
}E[2*10010];
int p[1010],eid;
void init()
{
    memset(p,-1,sizeof(p));
    eid=0;
}
void inser(int u,int v,int len)
{
    E[eid].v=v;
    E[eid].len=len;
    E[eid].next=p[u];
    p[u]=eid++;
}
int dis[1010];*/
//bool vis[1010];
ll pow_mod(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res=res*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return res%mod;
}
int n,m;
int a[1010];
int ans;
int main(){
  SIS;
  int t;
  cin>>t;
  while(t--)
  {
       cin>>n;

  int cnt=0;
     ans=0;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
      ans+=a[i];
      if(a[i]==0)
        cnt++;
  }
  if(cnt==0&&ans<0||cnt==0&&ans>0)
  {
      cout<<0<<endl;
  }
  else if(cnt==0&&ans==0)
  {
      cout<<1<<endl;
  }
  else if(cnt!=0&&ans<0)
  {
      cout<<max(cnt,1-ans)<<endl;
  }
  else if(cnt!=0&&ans==0)
  {
      cout<<cnt<<endl;
  }
  else if(cnt!=0&&ans>0)
  {
      cout<<cnt<<endl;
  }

  }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <set>
#include <sstream>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define MAXX 100005
#define SIS std::ios::sync_with_stdio(false)
#define ll long long
#define INF 0x3f3f3f3f
//#include<bits/stdc++.h>
using namespace std;
//const int MAX =100;
const int mod=1e9+7;
/*const double PI=3.14159265359;
const double esp=1e-5;
//int mp[MAXX];
int  a[200005],b[100005],c[100005];
int n,m,d,x,cnt=0,k;
int num[10005];
int N,M,L;
struct node{
   int v,len,w;
   int next;
}E[2*10010];
int p[1010],eid;
void init()
{
    memset(p,-1,sizeof(p));
    eid=0;
}
void inser(int u,int v,int len)
{
    E[eid].v=v;
    E[eid].len=len;
    E[eid].next=p[u];
    p[u]=eid++;
}
int dis[1010];*/
//bool vis[1010];
ll pow_mod(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res=res*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return res%mod;
}
int n,m;
int a[1010];
int ans;
int main(){
  SIS;
  int t;
  cin>>t;
  while(t--)
  {
       cin>>n;

  int cnt=0;
     ans=0;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
      ans+=a[i];
      if(a[i]==0)
        cnt++;
  }
  if(cnt==0&&ans>0)
  {
      cout<<0<<endl;
  }
  else if(cnt==0&&ans==0)
    cout<<1<<endl;
    else if(cnt==0&&ans<0)
        cout<<1-ans<<endl;
  else if(cnt!=0&&ans<0)
  {
       cout<<max(cnt,1-ans)<<endl;
       //cout<<2333;
  }

    else
        cout<<cnt<<endl;

  }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <set>
#include <sstream>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define MAXX 100005
#define SIS std::ios::sync_with_stdio(false)
#define ll long long
#define INF 0x3f3f3f3f
//#include<bits/stdc++.h>
using namespace std;
//const int MAX =100;
const int mod=1e9+7;
/*const double PI=3.14159265359;
const double esp=1e-5;
//int mp[MAXX];
int  a[200005],b[100005],c[100005];
int n,m,d,x,cnt=0,k;
int num[10005];
int N,M,L;
struct node{
   int v,len,w;
   int next;
}E[2*10010];
int p[1010],eid;
void init()
{
    memset(p,-1,sizeof(p));
    eid=0;
}
void inser(int u,int v,int len)
{
    E[eid].v=v;
    E[eid].len=len;
    E[eid].next=p[u];
    p[u]=eid++;
}
int dis[1010];*/
//bool vis[1010];
ll pow_mod(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res=res*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return res%mod;
}
int n,m;
ll dp[1010];
int a[1010];
int ans;
int main(){
  SIS;
  int t;
  cin>>t;
  while(t--)
  {
       cin>>n;

  int cnt=0;
  ans=0;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
      ans+=a[i];
      if(a[i]==0)
        cnt++;
  }
  if(!cnt&&ans>0)
  {
      cout<<0<<endl;
  }
  else if(!cnt&&ans==0)
    cout<<1<<endl;
  else if(cnt!=0&&ans<0)
  {
       cout<<max(cnt,1-ans)<<endl;
       //cout<<2333;
  }

    else
        cout<<cnt<<endl;

  }

    return 0;
}


#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <string>
#include <set>
#include <algorithm>
#pragma warning(disable:4996)
typedef long long ll;
using namespace std;
const int maxn = 2e5 + 5;

int main()
{
	int  N, n;
	string s;
	int a[10005];
	cin >> N;
	while (N--)
	{
		int sum = 0, sum1 = 1, num = 0;
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
			sum += a[i];
			if(a[i]==0)
			  sum1 =0;
			if (a[i] == 0)
				num++;
		}
		//cout << sum1 << endl;
		if (num == n)
			cout << n << endl;
		else
		{
			if (sum == 0 && sum1 == 0)///和积0
				cout << num << endl;
			else if (sum == 0 && sum1 != 0)//和0积不0
				cout << 1 << endl;
			else if (sum != 0 && sum1 == 0)
			{
				if (sum + num == 0)
					cout << num + 1 << endl;
				else
					cout << num << endl;
			}
			else if (sum != 0 && sum1 != 0)
				cout << 0 << endl;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,avx,avx2")

#define all(x) (x).begin(),(x).end()

void opting(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
}

inline long long inp(){
    long long x;
    cin >> x;
    return x;
}

void comping(vector<long long> &vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());

}

const long long maxn = 2e5 + 20, delta = 998244353, SQRT = 350, inf = 1e9;

vector<long long> D[maxn];
unordered_map<long long, long long> cnt[maxn];
long long anses[maxn];
vector<long long> a;

vector<long long> adj[maxn];
void add_edge(long long u, long long v){
    adj[u].push_back(v);
    adj[v].push_back(u);
}

void predo(){
    for(long long i = 1; i < maxn; i++)
        for(long long j = i; j < maxn; j += i)
            D[j].push_back(i);
}
void dfs(long long v, long long p){
    long long A = a[v];
    for(auto d : D[A]){
        anses[d]++;
        cnt[v][d]++;
    }

    for(auto u : adj[v])
        if(u != p){
            dfs(u, v);
            for(auto d : D[A]){
                anses[d] += (cnt[v][d] * cnt[u][d]);
                cnt[v][d] += cnt[u][d];
            }
        }
}

void input(){
    long long n = inp();
    for(long long i = 0; i < n; i++)
        a.push_back(inp());
    for(long long i = 1; i < n; i++)
        add_edge(inp()-1, inp()-1);
}

void solve(){
    dfs(0, 0);
}

void pstdo(){
    for(long long i = maxn - 1; i; i--)
        for(long long j = i * 2; j < maxn; j += i)
            anses[i] -= anses[j];
}

void print(){
    for(long long i = 1; i < maxn; i++)
        if(anses[i])
            cout << i << ' ' << anses[i] << '\n';
}
int main(){
    opting();

    predo();
    input();
    solve();
    pstdo();
    print();
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
int n, a[N];
int dd[N], sz[N], c[N], pd[N], cnt;
vector <int> ad[N], uoc[N];
int val[N], ans[N], dem[N];

void dfs(int u, int par) {
  cnt++; sz[u] = 1;
  for(auto &v : ad[u]) if(v != par && !dd[v]) dfs(v, u), sz[u] += sz[v];
}
int ctr(int u, int par) {
  for(auto &v : ad[u]) if(v != par && !dd[v] && sz[v] > cnt / 2) return ctr(v, u);
  return u;
}
void upd(int u, int par) {
  for(auto &v : uoc[val[u]]) ans[v] += dem[v];
  for(auto &v : ad[u]) {
    if(v != par && !dd[v]) upd(v, u);
  }
}
void take(int u, int par) {
  val[u] = __gcd(a[u], val[par]);
  for(auto &v : ad[u]) {
    if(v != par && !dd[v]) {
      take(v, u);
    }
  }
}
void Count(int u, int par, int x) {
  for(auto &v : uoc[val[u]]) dem[v] += x;
  for(auto &v : ad[u]) if(!dd[v] && v != par) Count(v, u, x);
}
void cen(int u, int par) {
  cnt = 0; dfs(u, u);
  int center = ctr(u, u);
  dd[center] = 1;
  val[center] = a[center];
  take(center, center);
  for(auto &v : uoc[val[center]]) dem[v]++;
  for(auto &v : ad[center]) {
    if(!dd[v]) {
      upd(v, v);
      Count(v, v, 1);
    }
  }
  for(auto &v : uoc[val[center]]) dem[v]--;
  for(auto &v : ad[center]) {
    if(!dd[v]) {
      Count(v, v, -1);
    }
  }
  for(auto &v : ad[center]) if(!dd[v]) cen(v, center);
}
main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n;
  for(int i = 1; i <= n; ++i) cin >> a[i];

  for(int i = 1; i < N; ++i) {
    for(int j = i; j < N; j += i) {
      uoc[j].push_back(i);
    }
  }

  for(int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    ad[u].push_back(v);
    ad[v].push_back(u);
  }
  cen(1, 1);
  for(int i = 1; i <= n; ++i) {
    for(auto &v : uoc[val[i]]) ans[v]++;
  }
  for(int i = N - 1; i >= 1; --i) {
    for(int j = i * 2; j < N; j += i) ans[i] -= ans[j];
  }
  for(int i = 1; i <= 2e5; ++i) {
    if(ans[i]) {
      cout << i << ' ' << ans[i] << '\n';
    }
  }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 2e5 + 5;
int n, a[N];
int dd[N], sz[N], c[N], pd[N], cnt;
vector <int> ad[N], uoc[N];
long long val[N], ans[N], dem[N];

void dfs(int u, int par) {
  cnt++; sz[u] = 1;
  for(auto &v : ad[u]) if(v != par && !dd[v]) dfs(v, u), sz[u] += sz[v];
}
int ctr(int u, int par) {
  for(auto &v : ad[u]) if(v != par && !dd[v] && sz[v] > cnt / 2) return ctr(v, u);
  return u;
}
void upd(int u, int par) {
  for(auto &v : uoc[val[u]]) ans[v] += dem[v];
  for(auto &v : ad[u]) {
    if(v != par && !dd[v]) upd(v, u);
  }
}
void take(int u, int par) {
  val[u] = __gcd(a[u], val[par]);
  for(auto &v : ad[u]) {
    if(v != par && !dd[v]) {
      take(v, u);
    }
  }
}
void Count(int u, int par, int x) {
  for(auto &v : uoc[val[u]]) dem[v] += x;
  for(auto &v : ad[u]) if(!dd[v] && v != par) Count(v, u, x);
}
void cen(int u, int par) {
  cnt = 0; dfs(u, u);
  int center = ctr(u, u);
  dd[center] = 1;
  val[center] = a[center];
  take(center, center);
  for(auto &v : uoc[val[center]]) dem[v]++;
  for(auto &v : ad[center]) {
    if(!dd[v]) {
      upd(v, v);
      Count(v, v, 1);
    }
  }
  for(auto &v : uoc[val[center]]) dem[v]--;
  for(auto &v : ad[center]) {
    if(!dd[v]) {
      Count(v, v, -1);
    }
  }
  for(auto &v : ad[center]) if(!dd[v]) cen(v, center);
}
main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n;
  for(int i = 1; i <= n; ++i) cin >> a[i];

  for(int i = 1; i < N; ++i) {
    for(int j = i; j < N; j += i) {
      uoc[j].push_back(i);
    }
  }

  for(int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    ad[u].push_back(v);
    ad[v].push_back(u);
  }
  cen(1, 1);
  for(int i = 1; i <= n; ++i) {
    for(auto &v : uoc[val[i]]) ans[v]++;
  }
  for(int i = N - 1; i >= 1; --i) {
    for(int j = i * 2; j < N; j += i) ans[i] -= ans[j];
  }
  for(int i = 1; i <= 2e5; ++i) {
    if(ans[i]) {
      cout << i << ' ' << ans[i] << '\n';
    }
  }
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
int n, a[N];
int dd[N], sz[N], c[N], pd[N], cnt;
vector <int> ad[N], uoc[N];
int val[N], ans[N], dem[N];

void dfs(int u, int par) {
  cnt++; sz[u] = 1;
  for(auto &v : ad[u]) if(v != par && !dd[v]) dfs(v, u), sz[u] += sz[v];
}
int ctr(int u, int par) {
  for(auto &v : ad[u]) if(v != par && !dd[v] && sz[v] > cnt / 2) return ctr(v, u);
  return u;
}
void upd(int u, int par) {
  for(auto &v : uoc[val[u]]) ans[v] += dem[v];
  for(auto &v : ad[u]) {
    if(v != par && !dd[v]) upd(v, u);
  }
}
void take(int u, int par) {
  val[u] = __gcd(a[u], val[par]);
  for(auto &v : ad[u]) {
    if(v != par && !dd[v]) {
      take(v, u);
    }
  }
}
void Count(int u, int par, int x) {
  for(auto &v : uoc[val[u]]) dem[v] += x;
  for(auto &v : ad[u]) if(!dd[v] && v != par) Count(v, u, x);
}
void cen(int u, int par) {
  cnt = 0; dfs(u, u);
  int center = ctr(u, u);
  dd[center] = 1;
  val[center] = a[center];
  take(center, center);
  for(auto &v : uoc[val[center]]) dem[v]++;
  for(auto &v : ad[center]) {
    if(!dd[v]) {
      upd(v, v);
      Count(v, v, 1);
    }
  }
  for(auto &v : uoc[val[center]]) dem[v]--;
  for(auto &v : ad[center]) {
    if(!dd[v]) {
      Count(v, v, -1);
    }
  }
  for(auto &v : ad[center]) if(!dd[v]) cen(v, center);
}
main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n;
  for(int i = 1; i <= n; ++i) cin >> a[i];

  for(int i = 1; i < N; ++i) {
    for(int j = i; j < N; ++j) {
      uoc[j].push_back(i);
    }
  }

  for(int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    ad[u].push_back(v);
    ad[v].push_back(u);
  }
  cen(1, 1);
  for(int i = 1; i <= n; ++i) {
    for(auto &v : uoc[val[i]]) ans[v]++;
  }
  for(int i = N - 1; i >= 1; --i) {
    for(int j = i * 2; j < N; j += i) ans[i] -= ans[j];
  }
  for(int i = 1; i <= 2e5; ++i) {
    if(ans[i]) {
      cout << i << ' ' << ans[i] << '\n';
    }
  }
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAX_N = 200005;

int n;
int a[MAX_N];
vector<int> g[MAX_N];
int vSize[MAX_N];
int pathGcd[MAX_N];
unordered_map<int, int> gcdCnt;
unordered_map<int, int> tmpGcdCnt;
ll result[MAX_N];

void findSizes(int u, int prev)
{
	vSize[u] = 1;
	for (int v : g[u])
		if (v != prev)
		{
			findSizes(v, u);
			vSize[u] += vSize[v];
		}
}

int findCentroid(int u, int prev, int start)
{
	int maxV = -1;
	for (int v : g[u])
		if (v != prev && vSize[v] > vSize[start] / 2 && vSize[v] > vSize[maxV])
			maxV = v;
	if (maxV == -1)
		return u;
	return findCentroid(maxV, u, start);
}

void calcPathGcd(int u, int prev)
{
	if (prev != -1)
		pathGcd[u] = gcd(pathGcd[prev], a[u]);
	gcdCnt[pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcPathGcd(v, u);
}

void calcTmpPathGcd(int u, int prev)
{
	tmpGcdCnt[pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcTmpPathGcd(v, u);
}

void calcResWithCentroid(int u, int prev, int c)
{
	result[gcd(a[c], pathGcd[u])] += 2;
	for (int v : g[u])
		if (v != prev)
			calcResWithCentroid(v, u, c);
}

void calcResult(int u, int prev)
{
	for (auto& p : gcdCnt)
	{
		int val = p.first, cnt = p.second;
		if (tmpGcdCnt.count(val))
			cnt -= tmpGcdCnt[val];
		int resGcd = gcd(val, pathGcd[u]);
		result[resGcd] += cnt;
	}

	for (int v : g[u])
		if (v != prev)
			calcResult(v, u);
}

void solve(int u)
{
	findSizes(u, -1);
	int c = findCentroid(u, -1, u);

	gcdCnt.clear();
	pathGcd[c] = a[c];
	calcPathGcd(c, -1);
	for (int v : g[c])
	{
		tmpGcdCnt.clear();
		tmpGcdCnt[a[c]]++;
		calcTmpPathGcd(v, c);
		calcResult(v, c);
		calcResWithCentroid(v, c, c);
	}
	result[a[c]] += 2;

	vector<int> nextV;
	for (int v : g[c])
	{
		for (int i = 0; i < (int)g[v].size(); i++)
			if (g[v][i] == c)
			{
				g[v].erase(g[v].begin() + i);
				break;
			}
	}
	swap(g[c], nextV);
	for (int v : nextV)
		solve(v);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0);
	for (int i = 0; i < MAX_N; i++)
		if (result[i] != 0)
			cout << i << " " << (result[i] / 2LL) << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAX_N = 200005;

int n;
int a[MAX_N];
vector<int> g[MAX_N];
int vSize[MAX_N];
int pathGcd[MAX_N];
unordered_map<int, int> gcdCnt;
unordered_map<int, int> tmpGcdCnt[MAX_N];
ll result[MAX_N];

void findSizes(int u, int prev)
{
	vSize[u] = 1;
	for (int v : g[u])
		if (v != prev)
		{
			findSizes(v, u);
			vSize[u] += vSize[v];
		}
}

int findCentroid(int u, int prev, int start)
{
	int maxV = -1;
	for (int v : g[u])
		if (v != prev && vSize[v] > vSize[start] / 2 && vSize[v] > vSize[maxV])
			maxV = v;
	if (maxV == -1)
		return u;
	return findCentroid(maxV, u, start);
}

void calcPathGcd(int u, int prev, int start, int c)
{
	if (prev != -1)
	{
		pathGcd[u] = gcd(pathGcd[prev], a[u]);
		gcdCnt[pathGcd[u]]++;
	}
	if (start != -1)
		tmpGcdCnt[start][pathGcd[u]]++;
	if (u == c)
	{
		for (int v : g[u])
			if (v != prev)
				calcPathGcd(v, u, v, c);
	}
	else
	{
		for (int v : g[u])
			if (v != prev)
				calcPathGcd(v, u, start, c);
	}
}

void calcResWithCentroid(int u, int prev, int c)
{
	result[gcd(a[c], pathGcd[u])] += 2;
	for (int v : g[u])
		if (v != prev)
			calcResWithCentroid(v, u, c);
}

void solve(int u)
{
	findSizes(u, -1);
	int c = findCentroid(u, -1, u);

	gcdCnt.clear();
	for (int v : g[c])
	    tmpGcdCnt[v].clear();
	pathGcd[c] = a[c];
	calcPathGcd(c, -1, -1, c);
	for (int v : g[c])
	{
		for (auto& p1 : tmpGcdCnt[v])
			for (auto& p2 : gcdCnt)
			{
				int val = gcd(p1.first, p2.first);
				ll cnt = (ll)p1.second * (p2.second - (tmpGcdCnt[v].count(p2.first) ? tmpGcdCnt[v][p2.first] : 0));
				result[val] += cnt;
			}
		calcResWithCentroid(v, c, c);
	}
	result[a[c]] += 2;

	vector<int> nextV;
	for (int v : g[c])
	{
		for (int i = 0; i < (int)g[v].size(); i++)
			if (g[v][i] == c)
			{
				g[v].erase(g[v].begin() + i);
				break;
			}
	}
	swap(g[c], nextV);
	for (int v : nextV)
		solve(v);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0);
	for (int i = 0; i < MAX_N; i++)
		if (result[i] != 0)
			cout << i << " " << (result[i] / 2LL) << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAX_N = 200005;

int n;
int a[MAX_N];
vector<int> g[MAX_N];
int vSize[MAX_N];
int pathGcd[MAX_N];
map<int, int> gcdCnt;
map<int, int> tmpGcdCnt[MAX_N];
ll result[MAX_N];

void findSizes(int u, int prev)
{
	vSize[u] = 1;
	for (int v : g[u])
		if (v != prev)
		{
			findSizes(v, u);
			vSize[u] += vSize[v];
		}
}

int findCentroid(int u, int prev, int start)
{
	int maxV = -1;
	for (int v : g[u])
		if (v != prev && vSize[v] > vSize[start] / 2 && vSize[v] > vSize[maxV])
			maxV = v;
	if (maxV == -1)
		return u;
	return findCentroid(maxV, u, start);
}

void calcPathGcd(int u, int prev, int start, int c)
{
	if (prev != -1)
	{
		pathGcd[u] = gcd(pathGcd[prev], a[u]);
		gcdCnt[pathGcd[u]]++;
	}
	if (start != -1)
		tmpGcdCnt[start][pathGcd[u]]++;
	if (u == c)
	{
		for (int v : g[u])
			if (v != prev)
				calcPathGcd(v, u, v, c);
	}
	else
	{
		for (int v : g[u])
			if (v != prev)
				calcPathGcd(v, u, start, c);
	}
}

void calcResWithCentroid(int u, int prev, int c)
{
	result[gcd(a[c], pathGcd[u])] += 2;
	for (int v : g[u])
		if (v != prev)
			calcResWithCentroid(v, u, c);
}

void solve(int u)
{
	findSizes(u, -1);
	int c = findCentroid(u, -1, u);

	gcdCnt.clear();
	for (int v : g[c])
	    tmpGcdCnt[v].clear();
	pathGcd[c] = a[c];
	calcPathGcd(c, -1, -1, c);
	for (int v : g[c])
	{
		for (auto& p1 : tmpGcdCnt[v])
			for (auto& p2 : gcdCnt)
			{
				int val = gcd(p1.first, p2.first);
				ll cnt = (ll)p1.second * (p2.second - (tmpGcdCnt[v].count(p2.first) ? tmpGcdCnt[v][p2.first] : 0));
				result[val] += cnt;
			}
		calcResWithCentroid(v, c, c);
	}
	result[a[c]] += 2;

	vector<int> nextV;
	for (int v : g[c])
	{
		for (int i = 0; i < (int)g[v].size(); i++)
			if (g[v][i] == c)
			{
				g[v].erase(g[v].begin() + i);
				break;
			}
	}
	swap(g[c], nextV);
	for (int v : nextV)
		solve(v);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0);
	for (int i = 0; i < MAX_N; i++)
		if (result[i] != 0)
			cout << i << " " << (result[i] / 2LL) << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAX_N = 200005;

int n;
int a[MAX_N];
vector<int> g[MAX_N];
int vSize[MAX_N];
int pathGcd[MAX_N];
unordered_map<int, int> gcdCnt;
unordered_map<int, int> tmpGcdCnt[MAX_N];
ll result[MAX_N];

void findSizes(int u, int prev)
{
	vSize[u] = 1;
	for (int v : g[u])
		if (v != prev)
		{
			findSizes(v, u);
			vSize[u] += vSize[v];
		}
}

int findCentroid(int u, int prev, int start)
{
	int maxV = -1;
	for (int v : g[u])
		if (v != prev && vSize[v] > vSize[start] / 2 && vSize[v] > vSize[maxV])
			maxV = v;
	if (maxV == -1)
		return u;
	return findCentroid(maxV, u, start);
}

void calcPathGcd(int u, int prev, int start, int c)
{
	if (prev != -1)
		pathGcd[u] = gcd(pathGcd[prev], a[u]);
	gcdCnt[pathGcd[u]]++;
	if (start != -1)
		tmpGcdCnt[start][pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcPathGcd(v, u, u == c ? v : start, c);
}

void calcResWithCentroid(int u, int prev, int c)
{
	result[gcd(a[c], pathGcd[u])] += 2;
	for (int v : g[u])
		if (v != prev)
			calcResWithCentroid(v, u, c);
}

void calcResult(int u, int prev, int start)
{
	for (auto& p : gcdCnt)
	{
		int val = p.first, cnt = p.second;
		if (tmpGcdCnt[start].count(val))
			cnt -= tmpGcdCnt[start][val];
		int resGcd = gcd(val, pathGcd[u]);
		result[resGcd] += cnt;
	}

	for (int v : g[u])
		if (v != prev)
			calcResult(v, u, start);
}

void solve(int u)
{
	findSizes(u, -1);
	int c = findCentroid(u, -1, u);

	gcdCnt.clear();
	for (int v : g[c])
	{
		tmpGcdCnt[v].clear();
		tmpGcdCnt[v][a[c]]++;
	}
	pathGcd[c] = a[c];
	calcPathGcd(c, -1, -1, c);
	for (int v : g[c])
	{
		calcResult(v, c, v);
		calcResWithCentroid(v, c, c);
	}
	result[a[c]] += 2;

	vector<int> nextV;
	for (int v : g[c])
	{
		for (int i = 0; i < (int)g[v].size(); i++)
			if (g[v][i] == c)
			{
				g[v].erase(g[v].begin() + i);
				break;
			}
	}
	swap(g[c], nextV);
	for (int v : nextV)
		solve(v);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0);
	for (int i = 0; i < MAX_N; i++)
		if (result[i] != 0)
			cout << i << " " << (result[i] / 2LL) << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAX_N = 200005;

int a[MAX_N];
vector<int> g[MAX_N];
int vSize[MAX_N];
int pathGcd[MAX_N];
map<int, int> gcdCnt;
map<int, int> tmpGcdCnt;
ll result[MAX_N];

void findSizes(int u, int prev)
{
	vSize[u] = 1;
	for (int v : g[u])
		if (v != prev)
		{
			findSizes(v, u);
			vSize[u] += vSize[v];
		}
}

int findCentroid(int u, int prev)
{
	int maxV = -1;
	for (int v : g[u])
		if (v != prev && vSize[v] > vSize[u] / 2 && vSize[v] > vSize[maxV])
			maxV = v;
	if (maxV == -1)
		return u;
	return findCentroid(maxV, u);
}

void calcPathGcd(int u, int prev)
{
	if (prev != -1)
		pathGcd[u] = gcd(pathGcd[prev], a[u]);
	gcdCnt[pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcPathGcd(v, u);
}

void calcTmpPathGcd(int u, int prev)
{
	tmpGcdCnt[pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcTmpPathGcd(v, u);
}

void calcResWithCentroid(int u, int prev, int c)
{
	result[gcd(a[c], pathGcd[u])] += 2;
	for (int v : g[u])
		if (v != prev)
			calcResWithCentroid(v, u, c);
}

void calcResult(int u, int prev)
{
	for (auto& p : gcdCnt)
	{
		int val = p.first, cnt = p.second;
		if (tmpGcdCnt.count(val))
			cnt -= tmpGcdCnt[val];
		int resGcd = gcd(val, pathGcd[u]);
		result[resGcd] += cnt;
	}

	for (int v : g[u])
		if (v != prev)
			calcResult(v, u);
}

void solve(int u)
{
	findSizes(u, -1);
	int c = findCentroid(u, -1);

	gcdCnt.clear();
	pathGcd[c] = a[c];
	calcPathGcd(c, -1);
	for (int v : g[c])
	{
		tmpGcdCnt.clear();
		tmpGcdCnt[a[c]]++;
		calcTmpPathGcd(v, c);
		calcResult(v, c);
		calcResWithCentroid(v, c, c);
	}
	result[a[c]] += 2;

	vector<int> nextV;
	for (int v : g[c])
	{
		for (int i = 0; i < (int)g[v].size(); i++)
			if (g[v][i] == c)
			{
				g[v].erase(g[v].begin() + i);
				break;
			}
	}
	swap(g[c], nextV);
	for (int v : nextV)
		solve(v);
}

int main()
{
	ios::sync_with_stdio(false);
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0);
	for (int i = 0; i < MAX_N; i++)
		if (result[i] != 0)
			cout << i << " " << (result[i] / 2LL) << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAX_N = 200005;

int n;
int a[MAX_N];
vector<int> g[MAX_N];
int vSize[MAX_N];
int pathGcd[MAX_N];
unordered_map<int, int> gcdCnt;
unordered_map<int, int> tmpGcdCnt;
ll result[MAX_N];

void findSizes(int u, int prev)
{
	vSize[u] = 1;
	for (int v : g[u])
		if (v != prev)
		{
			findSizes(v, u);
			vSize[u] += vSize[v];
		}
}

int findCentroid(int u, int prev, int start)
{
	int maxV = -1;
	for (int v : g[u])
		if (v != prev && vSize[v] > vSize[start] / 2 && vSize[v] > vSize[maxV])
			maxV = v;
	if (maxV == -1)
		return u;
	return findCentroid(maxV, u, start);
}

void calcPathGcd(int u, int prev)
{
	if (prev != -1)
		pathGcd[u] = gcd(pathGcd[prev], a[u]);
	gcdCnt[pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcPathGcd(v, u);
}

void calcTmpPathGcd(int u, int prev)
{
	tmpGcdCnt[pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcTmpPathGcd(v, u);
}

void calcResWithCentroid(int u, int prev, int c)
{
	result[gcd(a[c], pathGcd[u])] += 2;
	for (int v : g[u])
		if (v != prev)
			calcResWithCentroid(v, u, c);
}

void calcResult(int u, int prev)
{
	for (auto& p : gcdCnt)
	{
		int val = p.first, cnt = p.second;
		if (tmpGcdCnt.count(val))
			cnt -= tmpGcdCnt[val];
		int resGcd = gcd(val, pathGcd[u]);
		result[resGcd] += cnt;
	}

	for (int v : g[u])
		if (v != prev)
			calcResult(v, u);
}

void solve(int u)
{
	findSizes(u, -1);
	int c = findCentroid(u, -1, u);

	gcdCnt = unordered_map<int, int>();
	pathGcd[c] = a[c];
	calcPathGcd(c, -1);
	for (int v : g[c])
	{
		tmpGcdCnt = unordered_map<int, int>();
		tmpGcdCnt[a[c]]++;
		calcTmpPathGcd(v, c);
		calcResult(v, c);
		calcResWithCentroid(v, c, c);
	}
	result[a[c]] += 2;

	vector<int> nextV;
	for (int v : g[c])
	{
		for (int i = 0; i < (int)g[v].size(); i++)
			if (g[v][i] == c)
			{
				g[v].erase(g[v].begin() + i);
				break;
			}
	}
	swap(g[c], nextV);
	for (int v : nextV)
		solve(v);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0);
	for (int i = 0; i < MAX_N; i++)
		if (result[i] != 0)
			cout << i << " " << (result[i] / 2LL) << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAX_N = 200005;

int n;
int a[MAX_N];
vector<int> g[MAX_N];
int vSize[MAX_N];
int pathGcd[MAX_N];
unordered_map<int, int> gcdCnt;
unordered_map<int, int> pathGcdCnt[MAX_N];
ll result[MAX_N];

void findSizes(int u, int prev)
{
	vSize[u] = 1;
	for (int v : g[u])
		if (v != prev)
		{
			findSizes(v, u);
			vSize[u] += vSize[v];
		}
}

int findCentroid(int u, int prev, int start)
{
	int maxV = -1;
	for (int v : g[u])
		if (v != prev && vSize[v] > vSize[start] / 2 && vSize[v] > vSize[maxV])
			maxV = v;
	if (maxV == -1)
		return u;
	return findCentroid(maxV, u, start);
}

void calcPathGcd(int u, int prev, int start)
{
	pathGcd[u] = gcd(pathGcd[prev], a[u]);
	gcdCnt[pathGcd[u]]++;
	pathGcdCnt[start][pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcPathGcd(v, u, start);
}

void calcResWithCentroid(int u, int prev, int c)
{
	result[gcd(a[c], pathGcd[u])] += 2;
	for (int v : g[u])
		if (v != prev)
			calcResWithCentroid(v, u, c);
}

void solve(int u)
{
	findSizes(u, -1);
	int c = findCentroid(u, -1, u);

	gcdCnt.clear();
	for (int v : g[c])
	    pathGcdCnt[v].clear();
	pathGcd[c] = a[c];
	for (int v : g[c])
		calcPathGcd(v, c, v);
	for (int v : g[c])
	{
		for (auto const& p1 : pathGcdCnt[v])
			for (auto const& p2 : gcdCnt)
			{
				int val = gcd(p1.first, p2.first);
				int cnt = p2.second;
				if (pathGcdCnt[v].count(p2.first))
					cnt -= pathGcdCnt[v][p2.first];
				result[val] += (ll)cnt * (ll)p1.second;
			}
		calcResWithCentroid(v, c, c);
	}
	result[a[c]] += 2;

	vector<int> nextV;
	for (int v : g[c])
	{
		for (int i = 0; i < (int)g[v].size(); i++)
			if (g[v][i] == c)
			{
				g[v].erase(g[v].begin() + i);
				break;
			}
	}
	swap(g[c], nextV);
	for (int v : nextV)
		solve(v);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0);
	for (int i = 0; i < MAX_N; i++)
		if (result[i] != 0)
			cout << i << " " << (result[i] / 2LL) << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAX_N = 200005;

int n;
int a[MAX_N];
vector<int> g[MAX_N];
int vSize[MAX_N];
int pathGcd[MAX_N];
map<int, int> gcdCnt;
map<int, int> tmpGcdCnt;
ll result[MAX_N];

void findSizes(int u, int prev)
{
	vSize[u] = 1;
	for (int v : g[u])
		if (v != prev)
		{
			findSizes(v, u);
			vSize[u] += vSize[v];
		}
}

int findCentroid(int u, int prev, int start)
{
	int maxV = -1;
	for (int v : g[u])
		if (v != prev && vSize[v] > vSize[start] / 2 && vSize[v] > vSize[maxV])
			maxV = v;
	if (maxV == -1)
		return u;
	return findCentroid(maxV, u, start);
}

void calcPathGcd(int u, int prev)
{
	if (prev != -1)
		pathGcd[u] = gcd(pathGcd[prev], a[u]);
	gcdCnt[pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcPathGcd(v, u);
}

void calcTmpPathGcd(int u, int prev)
{
	tmpGcdCnt[pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcTmpPathGcd(v, u);
}

void calcResWithCentroid(int u, int prev, int c)
{
	result[gcd(a[c], pathGcd[u])] += 2;
	for (int v : g[u])
		if (v != prev)
			calcResWithCentroid(v, u, c);
}

void calcResult(int u, int prev)
{
	for (auto& p : gcdCnt)
	{
		int val = p.first, cnt = p.second;
		if (tmpGcdCnt.count(val))
			cnt -= tmpGcdCnt[val];
		int resGcd = gcd(val, pathGcd[u]);
		result[resGcd] += cnt;
	}

	for (int v : g[u])
		if (v != prev)
			calcResult(v, u);
}

void solve(int u)
{
	findSizes(u, -1);
	int c = findCentroid(u, -1, u);

	gcdCnt.clear();
	pathGcd[c] = a[c];
	calcPathGcd(c, -1);
	for (int v : g[c])
	{
		tmpGcdCnt.clear();
		tmpGcdCnt[a[c]]++;
		calcTmpPathGcd(v, c);
		calcResult(v, c);
		calcResWithCentroid(v, c, c);
	}
	result[a[c]] += 2;

	vector<int> nextV;
	for (int v : g[c])
	{
		for (int i = 0; i < (int)g[v].size(); i++)
			if (g[v][i] == c)
			{
				g[v].erase(g[v].begin() + i);
				break;
			}
	}
	swap(g[c], nextV);
	for (int v : nextV)
		solve(v);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0);
	for (int i = 0; i < MAX_N; i++)
		if (result[i] != 0)
			cout << i << " " << (result[i] / 2LL) << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAX_N = 200005;

int a[MAX_N];
vector<int> g[MAX_N];
int vSize[MAX_N];
int pathGcd[MAX_N];
map<int, int> gcdCnt;
map<int, int> tmpGcdCnt;
ll result[MAX_N];

void findSizes(int u, int prev)
{
	vSize[u] = 1;
	for (int v : g[u])
		if (v != prev)
		{
			findSizes(v, u);
			vSize[u] += vSize[v];
		}
}

int findCentroid(int u, int prev)
{
	int maxV = -1;
	for (int v : g[u])
		if (v != prev && vSize[v] > vSize[u] / 2 && vSize[v] > vSize[maxV])
			maxV = v;
	if (maxV == -1)
		return u;
	return findCentroid(maxV, u);
}

void calcPathGcd(int u, int prev)
{
	if (prev != -1)
		pathGcd[u] = gcd(pathGcd[prev], a[u]);
	gcdCnt[pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcPathGcd(v, u);
}

void calcTmpPathGcd(int u, int prev)
{
	tmpGcdCnt[pathGcd[u]]++;
	for (int v : g[u])
		if (v != prev)
			calcTmpPathGcd(v, u);
}

void calcResWithCentroid(int u, int prev, int c)
{
	result[gcd(a[c], pathGcd[u])] += 2;
	for (int v : g[u])
		if (v != prev)
			calcResWithCentroid(v, u, c);
}

void calcResult(int u, int prev)
{
	for (auto& p : gcdCnt)
	{
		int val = p.first, cnt = p.second;
		if (tmpGcdCnt.count(val))
			cnt -= tmpGcdCnt[val];
		int resGcd = gcd(val, pathGcd[u]);
		result[resGcd] += cnt;
	}

	for (int v : g[u])
		if (v != prev)
			calcResult(v, u);
}

void solve(int u)
{
	memset(vSize, 0, sizeof(int) * MAX_N);
	findSizes(u, -1);
	int c = findCentroid(u, -1);

	gcdCnt.clear();
	pathGcd[c] = a[c];
	calcPathGcd(c, -1);
	for (int v : g[c])
	{
		tmpGcdCnt.clear();
		tmpGcdCnt[a[c]]++;
		calcTmpPathGcd(v, c);
		calcResult(v, c);
		calcResWithCentroid(v, c, c);
	}
	result[a[c]] += 2;

	vector<int> nextV;
	for (int v : g[c])
	{
		for (int i = 0; i < (int)g[v].size(); i++)
			if (g[v][i] == c)
			{
				g[v].erase(g[v].begin() + i);
				break;
			}
	}
	swap(g[c], nextV);
	for (int v : nextV)
		solve(v);
}

int main()
{
	ios::sync_with_stdio(false);
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0);
	for (int i = 0; i < MAX_N; i++)
		if (result[i] != 0)
			cout << i << " " << (result[i] / 2LL) << endl;
}


/*
    Author: isaf27 (Ivan Safonov)
*/

//#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-11;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 2 * 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    ll ans = 1;
    while (k)
    {
        if (k & 1) ans = (ans * a) % MOD;
        ans = (ans * ans) % MOD;
        k >>= 1;
    }
    return ans;
}

//random
mt19937 rnd(239);

//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 1e6 + 239;

bool can[M], used[M];
int n, a[M];
vector<int> ids[M];
vector<int> v[M];
ll ans[M], sz;

void dfs(int p)
{
    used[p] = true;
    sz++;
    for (int i : v[p])
        if (can[i] && !used[i])
            dfs(i);
}

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastIO;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        ids[a[i]].push_back(i);
    for (int i = 0; i < n - 1; i++)
    {
        int s, f;
        cin >> s >> f;
        s--, f--;
        v[s].push_back(f);
        v[f].push_back(s);
    }
    memset(can, 0, sizeof(can));
    memset(used, 0, sizeof(used));
    for (int i = 1; i < M; i++)
    {
        vector<int> now;
        for (int x = i; x < M; x += i)
            for (int t : ids[x])
                now.push_back(t);
        for (int t : now) can[t] = true;
        ans[i] = 0;
        for (int t : now)
            if (!used[t])
            {
                sz = 0;
                dfs(t);
                ans[i] += (sz * (sz + 1)) / 2LL;
            }
        for (int t : now) can[t] = false;
        for (int t : now) used[t] = false;
    }
    for (int i = M - 1; i >= 1; i--)
        for (int x = 2 * i; x < M; x += i)
            ans[i] -= ans[x];
    for (int i = 1; i < M; i++)
        if (ans[i] != 0)
            cout << i << " " << ans[i] << "\n";
    return 0;
}


/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-11;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 2 * 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    ll ans = 1;
    while (k)
    {
        if (k & 1) ans = (ans * a) % MOD;
        ans = (ans * ans) % MOD;
        k >>= 1;
    }
    return ans;
}

//random
mt19937 rnd(239);

//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 1e6 + 239;

bool can[M], used[M];
int n, a[M];
vector<int> ids[M];
vector<int> v[M];
ll ans[M], sz;

inline void dfs(int p)
{
    used[p] = true;
    sz++;
    for (int i : v[p])
        if (can[i] && !used[i])
            dfs(i);
}

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastIO;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        ids[a[i]].push_back(i);
    for (int i = 0; i < n - 1; i++)
    {
        int s, f;
        cin >> s >> f;
        s--, f--;
        v[s].push_back(f);
        v[f].push_back(s);
    }
    memset(can, 0, sizeof(can));
    memset(used, 0, sizeof(used));
    for (int i = 1; i < M; i++)
    {
        vector<int> now;
        for (int x = i; x < M; x += i)
            for (int t : ids[x])
                now.push_back(t);
        for (int t : now) can[t] = true;
        ans[i] = 0;
        for (int t : now)
            if (!used[t])
            {
                sz = 0;
                dfs(t);
                ans[i] += (sz * (sz + 1)) / 2LL;
            }
        for (int t : now) can[t] = false;
        for (int t : now) used[t] = false;
    }
    for (int i = M - 1; i >= 1; i--)
        for (int x = 2 * i; x < M; x += i)
            ans[i] -= ans[x];
    for (int i = 1; i < M; i++)
        if (ans[i] != 0)
            cout << i << " " << ans[i] << "\n";
    return 0;
}


/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-11;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 2 * 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    ll ans = 1;
    while (k)
    {
        if (k & 1) ans = (ans * a) % MOD;
        ans = (ans * ans) % MOD;
        k >>= 1;
    }
    return ans;
}

//random
mt19937 rnd(239);

//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 1e6 + 239;

bool used[M];
int n, a[M];
vector<pair<int, int> > rb[M];
vector<int> ids[M];
vector<int> v[M];
ll ans[M], sz;

inline void dfs(int p)
{
    used[p] = true;
    sz++;
    for (int i : v[p])
        if (!used[i])
            dfs(i);
}

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastIO;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        ids[a[i]].push_back(i);
    for (int i = 0; i < n - 1; i++)
    {
        int s, f;
        cin >> s >> f;
        s--, f--;
        rb[__gcd(a[s], a[f])].push_back(make_pair(s, f));
    }
    memset(used, 0, sizeof(used));
    for (int i = 1; i < M; i++)
    {
        vector<int> now;
        for (int x = i; x < M; x += i)
            for (int t : ids[x])
                now.push_back(t);
        for (int x = i; x < M; x += i)
            for (pair<int, int> t : rb[x])
            {
                v[t.first].push_back(t.second);
                v[t.second].push_back(t.first);
            }
        ans[i] = 0;
        for (int t : now)
            if (!used[t])
            {
                sz = 0;
                dfs(t);
                ans[i] += (sz * (sz + 1)) / 2LL;
            }
        for (int t : now) v[t].clear();
        for (int t : now) used[t] = false;
    }
    for (int i = M - 1; i >= 1; i--)
        for (int x = 2 * i; x < M; x += i)
            ans[i] -= ans[x];
    for (int i = 1; i < M; i++)
        if (ans[i] != 0)
            cout << i << " " << ans[i] << "\n";
    return 0;
}


/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-6;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 2 * 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    if (k == 0) return 1;
    ll t = power(a, k >> 1);
    t = (t * t) % MOD;
    if (k & 1) t = (t * a) % MOD;
    return t;
}

//random
mt19937 rnd(239);

//constants
const int M = 1e6 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 101;

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastIO;

    return 0;
}


/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

/** Begin fast allocation */
const int MAX_MEM = 2e8;
int mpos = 0;
char mem[MAX_MEM];
inline void * operator new ( size_t n ) {
 	assert((mpos += n) <= MAX_MEM);
 	return (void *)(mem + mpos - n);
}
inline void operator delete ( void * ) { } // must have!
/** End fast allocation */

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-11;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 2 * 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    ll ans = 1;
    while (k)
    {
        if (k & 1) ans = (ans * a) % MOD;
        ans = (ans * ans) % MOD;
        k >>= 1;
    }
    return ans;
}

//random
mt19937 rnd(239);

//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 1e6 + 239;

bool can[M], used[M];
int n, a[M];
vector<int> ids[M];
vector<int> v[M];
ll ans[M], sz;

inline void dfs(int p)
{
    used[p] = true;
    sz++;
    for (int i : v[p])
        if (can[i] && !used[i])
            dfs(i);
}

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastIO;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        ids[a[i]].push_back(i);
    for (int i = 0; i < n - 1; i++)
    {
        int s, f;
        cin >> s >> f;
        s--, f--;
        v[s].push_back(f);
        v[f].push_back(s);
    }
    memset(can, 0, sizeof(can));
    memset(used, 0, sizeof(used));
    for (int i = 1; i < M; i++)
    {
        vector<int> now;
        for (int x = i; x < M; x += i)
            for (int t : ids[x])
                now.push_back(t);
        for (int t : now) can[t] = true;
        ans[i] = 0;
        for (int t : now)
            if (!used[t])
            {
                sz = 0;
                dfs(t);
                ans[i] += (sz * (sz + 1)) / 2LL;
            }
        for (int t : now) can[t] = false;
        for (int t : now) used[t] = false;
    }
    for (int i = M - 1; i >= 1; i--)
        for (int x = 2 * i; x < M; x += i)
            ans[i] -= ans[x];
    for (int i = 1; i < M; i++)
        if (ans[i] != 0)
            cout << i << " " << ans[i] << "\n";
    return 0;
}


/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); forn(i, 0, number) solve()

/** Begin fast allocation */
const int MAX_MEM = 4e8;
int mpos = 0;
char mem[MAX_MEM];
inline void * operator new ( size_t n ) {
 	assert((mpos += n) <= MAX_MEM);
 	return (void *)(mem + mpos - n);
}
inline void operator delete ( void * ) { } // must have!
/** End fast allocation */

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-11;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 2 * 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    ll ans = 1;
    while (k)
    {
        if (k & 1) ans = (ans * a) % MOD;
        ans = (ans * ans) % MOD;
        k >>= 1;
    }
    return ans;
}

//random
mt19937 rnd(239);

//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 1e6 + 239;

bool can[M], used[M];
int n, a[M];
vector<int> ids[M];
vector<int> v[M];
ll ans[M], sz;

inline void dfs(int p)
{
    used[p] = true;
    sz++;
    for (int i : v[p])
        if (can[i] && !used[i])
            dfs(i);
}

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastIO;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        ids[a[i]].push_back(i);
    for (int i = 0; i < n - 1; i++)
    {
        int s, f;
        cin >> s >> f;
        s--, f--;
        v[s].push_back(f);
        v[f].push_back(s);
    }
    memset(can, 0, sizeof(can));
    memset(used, 0, sizeof(used));
    for (int i = 1; i < M; i++)
    {
        vector<int> now;
        for (int x = i; x < M; x += i)
            for (int t : ids[x])
                now.push_back(t);
        for (int t : now) can[t] = true;
        ans[i] = 0;
        for (int t : now)
            if (!used[t])
            {
                sz = 0;
                dfs(t);
                ans[i] += (sz * (sz + 1)) / 2LL;
            }
        for (int t : now) can[t] = false;
        for (int t : now) used[t] = false;
    }
    for (int i = M - 1; i >= 1; i--)
        for (int x = 2 * i; x < M; x += i)
            ans[i] -= ans[x];
    for (int i = 1; i < M; i++)
        if (ans[i] != 0)
            cout << i << " " << ans[i] << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef int ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
vvi arr(200001);
vvi divisor(200001);
ll val[200001];
long long ans[200001];
bool visited[200001];
ll cnt = 0;
ll dfs(ll u,ll par,ll d)
{
    ll i;
    cnt++;
    visited[u] = 1;
    for(i=0;i<arr[u].size();i++)
    {
        ll v = arr[u][i];
        if(v==par or val[v]%d or visited[v])
            continue;
        dfs(v,u,d);
    }
}
signed main()
{
    fast;
    ll n;
    ll i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>val[i];
        for(j=1;j*j<=val[i];j++)
        {
            if(val[i]%j)
                continue;
            ll x = j;
            divisor[x].pb(i);
            if(j*j==val[i])
                continue;
            x = val[i]/j;
            divisor[x].pb(i);
        }
    }
    for(i=0;i<n-1;i++)
    {
        ll u,v;
        cin>>u>>v;
        arr[u].pb(v);
        arr[v].pb(u);
    }

    for(i=2;i<=200000;i++)
    {
        for(j=0;j<divisor[i].size();j++)
        {
            ll u = divisor[i][j];
            if(visited[u])
                continue;
            cnt = 0;
            dfs(u,0,i);
            ans[i] = ans[i] + (cnt*1LL*(cnt+1LL))/2;
        }
        for(j=0;j<divisor[i].size();j++)
        {
            ll u = divisor[i][j];
                visited[u] = 0;
        }
    }
    long long tot = (n*(n+1))/2;
    for(i=200000;i>=2;i--)
    {
        for(j=2*i;j<=200000;j+=i)
            ans[i]-=ans[j];
        tot-=ans[i];
    }
    if(tot>0)
        cout<<1<<" "<<tot<<endl;
    for(i=2;i<=200000;i++)
        if(ans[i])
            cout<<i<<" "<<ans[i]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef int ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
vvi divisors(200001);
vvi arr(200001);
map < ll , pii > unionfind[200001];
ll val[200001];
ll root(ll x,ll u)
{
	if(unionfind[x][u].fi!=u)
		unionfind[x][u].fi = root(x,unionfind[x][u].fi);
	return unionfind[x][u].fi;
}
void uni(ll x,ll p,ll q)
{
	if(unionfind[x][p].sec>=unionfind[x][q].sec)
	{
		unionfind[x][p].sec+=unionfind[x][q].sec;
		unionfind[x][q].fi = unionfind[x][p].fi;
	}
	else
	{
		unionfind[x][q].sec+=unionfind[x][p].sec;
		unionfind[x][p].fi = unionfind[x][q].fi;
	}
}
ll dfs(ll u,ll par)
{
	ll i,j;
	for(i=0;i<arr[u].size();i++)
	{
		ll v = arr[u][i];
		if(v==par)
			continue;
		ll g = __gcd(val[u],val[v]);
		for(j=0;j<divisors[g].size();j++)
		{
			ll x = divisors[g][j];
			ll r1 = root(x,u);
			ll r2 = root(x,v);
			if(r1!=r2)
			{
				uni(x,r1,r2);
			}
		}
		dfs(v,u);

	}
}
signed main()
{
    fast;
    ll n;
    ll i,j;
    for(i=1;i<=2*100000;i++)
    {
    	for(j=i;j<=200000;j+=i)
    	{
    		divisors[j].pb(i);
    	}
    }
    cin>>n;
    for(i=1;i<=n;i++){
    	cin>>val[i];
    	for(j=0;j<divisors[val[i]].size();j++)
    	{
    		ll x = divisors[val[i]][j];
    		unionfind[x][i] = mp(i,1);
    	}
    }
    for(i=0;i<n-1;i++)
    {
    	ll u,v;
    	cin>>u>>v;
    	arr[u].pb(v);
    	arr[v].pb(u);
    }
    dfs(1,0);
    long long  ans[200001]={0};
    for(i=1;i<=200000;i++)
    {
    	for(map < ll , pii > ::iterator itr = unionfind[i].begin();itr!=unionfind[i].end();itr++)
    	{
    		pii temp = itr->sec;
    		if(temp.fi==itr->fi)
    		{
    			ans[i] = ans[i] + (temp.sec*1LL*(temp.sec+1LL))/2;
    		}
    	}
    }
    for(i=200000;i>=1;i--)
    {
    	for(j=2*i;j<=200000;j+=i)
    		ans[i]-=ans[j];
    }
    for(i=1;i<=200000;i++)
    	if(ans[i])
    		cout<<i<<" "<<ans[i]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
vvi divisors(200001);
vvi arr(200001);
map < ll , pii > unionfind[200001];
ll val[200001];
ll root(ll x,ll u)
{
	if(unionfind[x][u].fi!=u)
		unionfind[x][u].fi = root(x,unionfind[x][u].fi);
	return unionfind[x][u].fi;
}
void uni(ll x,ll p,ll q)
{
	if(unionfind[x][p].sec>=unionfind[x][q].sec)
	{
		unionfind[x][p].sec+=unionfind[x][q].sec;
		unionfind[x][q].fi = unionfind[x][p].fi;
	}
	else
	{
		unionfind[x][q].sec+=unionfind[x][p].sec;
		unionfind[x][p].fi = unionfind[x][q].fi;
	}
}
ll dfs(ll u,ll par)
{
	ll i,j;
	for(i=0;i<arr[u].size();i++)
	{
		ll v = arr[u][i];
		if(v==par)
			continue;
		ll g = __gcd(val[u],val[v]);
		for(j=0;j<divisors[g].size();j++)
		{
			ll x = divisors[g][j];
			ll r1 = root(x,u);
			ll r2 = root(x,v);
			if(r1!=r2)
			{
				uni(x,r1,r2);
			}
		}
		dfs(v,u);

	}
}
signed main()
{
    fast;
    ll n;
    ll i,j;
    for(i=1;i<=2*100000;i++)
    {
    	for(j=i;j<=200000;j+=i)
    	{
    		divisors[j].pb(i);
    	}
    }
    cin>>n;
    for(i=1;i<=n;i++){
    	cin>>val[i];
    	for(j=0;j<divisors[val[i]].size();j++)
    	{
    		ll x = divisors[val[i]][j];
    		unionfind[x][i] = mp(i,1);
    	}
    }
    for(i=0;i<n-1;i++)
    {
    	ll u,v;
    	cin>>u>>v;
    	arr[u].pb(v);
    	arr[v].pb(u);
    }
    dfs(1,0);
    ll ans[200001]={0};
    for(i=1;i<=200000;i++)
    {
    	for(map < ll , pii > ::iterator itr = unionfind[i].begin();itr!=unionfind[i].end();itr++)
    	{
    		pii temp = itr->sec;
    		if(temp.fi==itr->fi)
    		{
    			ans[i] = ans[i] + (temp.sec*(temp.sec+1))/2;
    		}
    	}
    }
    for(i=200000;i>=1;i--)
    {
    	for(j=2*i;j<=200000;j+=i)
    		ans[i]-=ans[j];
    }
    for(i=1;i<=200000;i++)
    	if(ans[i])
    		cout<<i<<" "<<ans[i]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef int ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
vvi arr(200001);
vvi divisor(200001);
ll val[200001];
long long ans[200001];
bool visited[200001];
ll cnt = 0;
ll dfs(ll u,ll par,ll d)
{
    ll i;
    cnt++;
    visited[u] = 1;
    for(i=0;i<arr[u].size();i++)
    {
        ll v = arr[u][i];
        if(v==par or val[v]%d or visited[v])
            continue;
        dfs(v,u,d);
    }
}
signed main()
{
    fast;
    ll n;
    ll i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>val[i];
        for(j=1;j*j<=val[i];j++)
        {
            if(val[i]%j)
                continue;
            ll x = j;
            divisor[x].pb(i);
            if(j*j==val[i])
                continue;
            x = val[i]/j;
            divisor[x].pb(i);
        }
    }
    for(i=0;i<n-1;i++)
    {
        ll u,v;
        cin>>u>>v;
        arr[u].pb(v);
        arr[v].pb(u);
    }

    for(i=2;i<=200000;i++)
    {
        for(j=0;j<divisor[i].size();j++)
        {
            ll u = divisor[i][j];
            if(visited[u])
                continue;
            cnt = 0;
            dfs(u,0,i);
            ans[i] = ans[i] + (cnt*1LL*(cnt+1LL))/2;
        }
        for(j=0;j<divisor[i].size();j++)
        {
            ll u = divisor[i][j];
                visited[u] = 0;
        }
    }
    long long tot = (n*(n+1))/2;
    for(i=200000;i>=2;i--)
    {
        for(j=2*i;j<=200000;j+=i)
            ans[i]-=ans[j];
        tot-=ans[i];
    }
    if(tot)
        cout<<1<<" "<<tot<<endl;
    for(i=2;i<=200000;i++)
        if(ans[i])
            cout<<i<<" "<<ans[i]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef int ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
vvi divisors(200001);
vvi arr(200001);
map < ll , pii > unionfind[200001];
ll val[200001];
long long ans[200001];
ll root(ll x,ll u)
{
    if(unionfind[x][u].fi!=u)
        unionfind[x][u].fi = root(x,unionfind[x][u].fi);
    return unionfind[x][u].fi;
}
void uni(ll x,ll p,ll q)
{
    if(unionfind[x][p].sec>=unionfind[x][q].sec)
    {
        unionfind[x][p].sec+=unionfind[x][q].sec;
        unionfind[x][q].fi = unionfind[x][p].fi;
    }
    else
    {
        unionfind[x][q].sec+=unionfind[x][p].sec;
        unionfind[x][p].fi = unionfind[x][q].fi;
    }
}
ll dfs(ll u,ll par)
{
    ll i,j;
    for(i=0;i<arr[u].size();i++)
    {
        ll v = arr[u][i];
        if(v==par)
            continue;
        ll g = __gcd(val[u],val[v]);
        for(j=0;j<divisors[g].size();j++)
        {
            ll x = divisors[g][j];
            ll r1 = root(x,u);
            ll r2 = root(x,v);
            if(r1!=r2)
            {
                uni(x,r1,r2);
            }
        }
        dfs(v,u);

    }
}
signed main()
{
    fast;
    ll n;
    ll i,j;
    for(i=2;i<=2*100000;i++)
    {
        for(j=i;j<=200000;j+=i)
        {
            divisors[j].pb(i);
        }
    }
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>val[i];
        for(j=0;j<divisors[val[i]].size();j++)
        {
            ll x = divisors[val[i]][j];
            unionfind[x][i] = mp(i,1);
        }
    }
    for(i=0;i<n-1;i++)
    {
        ll u,v;
        cin>>u>>v;
        arr[u].pb(v);
        arr[v].pb(u);
    }
    dfs(1,0);
    for(i=2;i<=200000;i++)
    {
        for(map < ll , pii > ::iterator itr = unionfind[i].begin();itr!=unionfind[i].end();itr++)
        {
            pii temp = itr->sec;
            if(temp.fi==itr->fi)
            {
                ans[i] = ans[i] + (temp.sec*1LL*(temp.sec+1LL))/2;
            }
        }
    }
    long long tot = (n*(n+1))/2;
    for(i=200000;i>=2;i--)
    {
        for(j=2*i;j<=200000;j+=i)
            ans[i]-=ans[j];
        tot-=ans[i];
    }
    if(tot)
        cout<<1<<" "<<tot<<endl;
    for(i=2;i<=200000;i++)
        if(ans[i])
            cout<<i<<" "<<ans[i]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef int ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
vvi arr(200001);
vvi divisor(200001);
ll val[200001];
long long ans[200001];
bool visited[200001];
ll cnt = 0;
ll dfs(ll u,ll par,ll d)
{
    ll i;
    cnt++;
    visited[u] = 1;
    for(i=0;i<arr[u].size();i++)
    {
        ll v = arr[u][i];
        if(v==par or val[v]%d or visited[v])
            continue;
        dfs(v,u,d);
    }
}
signed main()
{
    fast;
    ll n;
    ll i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>val[i];
        for(j=1;j*j<=val[i];j++)
        {
            if(val[i]%j)
                continue;
            ll x = j;
            divisor[x].pb(i);
            if(j*j==val[i])
                continue;
            x = val[i]/j;
            divisor[x].pb(i);
        }
    }
    for(i=0;i<n-1;i++)
    {
        ll u,v;
        cin>>u>>v;
        arr[u].pb(v);
        arr[v].pb(u);
    }

    for(i=2;i<=200000;i++)
    {
        for(j=0;j<divisor[i].size();j++)
        {
            ll u = divisor[i][j];
            if(visited[u])
                continue;
            cnt = 0;
            dfs(u,0,i);
            ans[i] = ans[i] + (cnt*1LL*(cnt+1LL))/2;
        }

    }
    long long tot = (n*(n+1))/2;
    for(i=200000;i>=2;i--)
    {
        for(j=2*i;j<=200000;j+=i)
            ans[i]-=ans[j];
        tot-=ans[i];
    }
    if(tot)
        cout<<1<<" "<<tot<<endl;
    for(i=2;i<=200000;i++)
        if(ans[i])
            cout<<i<<" "<<ans[i]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef int ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
vvi arr(200001);
map < ll , pii > unionfind[200001];
ll val[200001];
long long ans[200001];
ll root(ll x,ll u)
{
    if(unionfind[x][u].fi!=u)
        unionfind[x][u].fi = root(x,unionfind[x][u].fi);
    return unionfind[x][u].fi;
}
void uni(ll x,ll p,ll q)
{
    if(unionfind[x][p].sec>=unionfind[x][q].sec)
    {
        unionfind[x][p].sec+=unionfind[x][q].sec;
        unionfind[x][q].fi = unionfind[x][p].fi;
    }
    else
    {
        unionfind[x][q].sec+=unionfind[x][p].sec;
        unionfind[x][p].fi = unionfind[x][q].fi;
    }
}
ll dfs(ll u,ll par)
{
    ll i,j;
    for(i=0;i<arr[u].size();i++)
    {
        ll v = arr[u][i];
        if(v==par)
            continue;
        ll g = __gcd(val[u],val[v]);
        for(j=1;j*j<=g;j++)
        {
            if(g%j)
                continue;
            ll x = j;
            ll r1 = root(x,u);
            ll r2 = root(x,v);
            if(r1!=r2)
            {
                uni(x,r1,r2);
            }
            x = g/j;
            r1 = root(x,u);
            r2 = root(x,v);
            if(r1!=r2)
            {
                uni(x,r1,r2);
            }

        }
        dfs(v,u);

    }
}
signed main()
{
    fast;
    ll n;
    ll i,j;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>val[i];
        for(j=1;j*j<=val[i];j++)
        {
            if(val[i]%j)
                continue;
            ll x = j;
            unionfind[x][i] = mp(i,1);
            if(j*j!=val[i])
                x = val[i]/j;
            unionfind[x][i] = mp(i,1);
        }
    }
    for(i=0;i<n-1;i++)
    {
        ll u,v;
        cin>>u>>v;
        arr[u].pb(v);
        arr[v].pb(u);
    }
    dfs(1,0);
    for(i=2;i<=200000;i++)
    {
        for(map < ll , pii > ::iterator itr = unionfind[i].begin();itr!=unionfind[i].end();itr++)
        {
            pii temp = itr->sec;
            if(temp.fi==itr->fi)
            {
                ans[i] = ans[i] + (temp.sec*1LL*(temp.sec+1LL))/2;
            }
        }
    }
    long long tot = (n*(n+1))/2;
    for(i=200000;i>=2;i--)
    {
        for(j=2*i;j<=200000;j+=i)
            ans[i]-=ans[j];
        tot-=ans[i];
    }
    if(tot)
        cout<<1<<" "<<tot<<endl;
    for(i=2;i<=200000;i++)
        if(ans[i])
            cout<<i<<" "<<ans[i]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef int ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
vvi divisors(200001);
vvi arr(200001);
map < ll , pii > unionfind[200001];
ll val[200001];
ll root(ll x,ll u)
{
	if(unionfind[x][u].fi!=u)
		unionfind[x][u].fi = root(x,unionfind[x][u].fi);
	return unionfind[x][u].fi;
}
void uni(ll x,ll p,ll q)
{
	if(unionfind[x][p].sec>=unionfind[x][q].sec)
	{
		unionfind[x][p].sec+=unionfind[x][q].sec;
		unionfind[x][q].fi = unionfind[x][p].fi;
	}
	else
	{
		unionfind[x][q].sec+=unionfind[x][p].sec;
		unionfind[x][p].fi = unionfind[x][q].fi;
	}
}
ll dfs(ll u,ll par)
{
	ll i,j;
	for(i=0;i<arr[u].size();i++)
	{
		ll v = arr[u][i];
		if(v==par)
			continue;
		ll g = __gcd(val[u],val[v]);
		for(j=0;j<divisors[g].size();j++)
		{
			ll x = divisors[g][j];
			ll r1 = root(x,u);
			ll r2 = root(x,v);
			if(r1!=r2)
			{
				uni(x,r1,r2);
			}
		}
		dfs(v,u);

	}
}
signed main()
{
    fast;
    ll n;
    ll i,j;
    for(i=2;i<=2*100000;i++)
    {
    	for(j=i;j<=200000;j+=i)
    	{
    		divisors[j].pb(i);
    	}
    }
    cin>>n;
    for(i=1;i<=n;i++){
    	cin>>val[i];
    	for(j=0;j<divisors[val[i]].size();j++)
    	{
    		ll x = divisors[val[i]][j];
    		unionfind[x][i] = mp(i,1);
    	}
    }
    for(i=0;i<n-1;i++)
    {
    	ll u,v;
    	cin>>u>>v;
    	arr[u].pb(v);
    	arr[v].pb(u);
    }
    dfs(1,0);
    long long  ans[200001]={0};
    for(i=2;i<=200000;i++)
    {
    	for(map < ll , pii > ::iterator itr = unionfind[i].begin();itr!=unionfind[i].end();itr++)
    	{
    		pii temp = itr->sec;
    		if(temp.fi==itr->fi)
    		{
    			ans[i] = ans[i] + (temp.sec*1LL*(temp.sec+1LL))/2;
    		}
    	}
    }
    long long tot = (n*(n+1))/2;
    for(i=200000;i>=2;i--)
    {
    	for(j=2*i;j<=200000;j+=i)
    		ans[i]-=ans[j];
    	tot-=ans[i];
    }
    if(tot)
    	cout<<1<<" "<<tot<<endl;
    for(i=2;i<=200000;i++)
    	if(ans[i])
    		cout<<i<<" "<<ans[i]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef int ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
vvi arr(200001);
vvi divisor(200001);
ll val[200001];
long long ans[200001];
bool visited[200001];
ll cnt = 0;
ll dfs(ll u,ll par,ll d)
{
    ll i;
    cnt++;
    visited[u] = 1;
    for(i=0;i<arr[u].size();i++)
    {
        ll v = arr[u][i];
        if(v==par or val[v]%d or visited[v])
            continue;
        dfs(v,u,d);
    }
}
signed main()
{
    fast;
    ll n;
    ll i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>val[i];
        for(j=1;j*j<=val[i];j++)
        {
            if(val[i]%j)
                continue;
            ll x = j;
            divisor[x].pb(i);
            if(j*j==val[i])
                continue;
            x = val[i]/j;
            divisor[x].pb(i);
        }
    }
    for(i=0;i<n-1;i++)
    {
        ll u,v;
        cin>>u>>v;
        arr[u].pb(v);
        arr[v].pb(u);
    }

    for(i=1;i<=200000;i++)
    {
        for(j=0;j<divisor[i].size();j++)
        {
            ll u = divisor[i][j];
            if(visited[u])
                continue;
            cnt = 0;
            dfs(u,0,i);
            ans[i] = ans[i] + (cnt*1LL*(cnt+1LL))/2;
        }
        for(j=0;j<divisor[i].size();j++)
        {
            ll u = divisor[i][j];
                visited[u] = 0;
        }
    }
    long long tot = (n*(n+1))/2;
    for(i=200000;i>=1;i--)
    {
        for(j=2*i;j<=200000;j+=i)
            ans[i]-=ans[j];
        tot-=ans[i];
    }
    for(i=1;i<=200000;i++)
        if(ans[i])
            cout<<i<<" "<<ans[i]<<endl;
}


#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;
using namespace std;
//mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

const int maxn = 200005;
int sz[maxn], mx[maxn], vis[maxn], a[maxn];
int N,rt;
vector<int> g[maxn];
void getrt(int u, int fa) {
    sz[u] = 1; mx[u] = 0;
    for(int v : g[u]) {
        if(vis[v] || v == fa) continue;
        getrt(v, u);
        sz[u] += sz[v];
        mx[u] = max(mx[u], sz[v]);
    }
    mx[u] = max(mx[u], N - sz[u]);
    if(mx[u] < mx[rt]) rt = u;
}
ll cnt[maxn];

int G[505][505];
int Gcd(int a,int b) {return b == 0 ? a : Gcd(b, a % b);}
void init() {
    for(int i=0;i<=500;++i) for(int j=0;j<=500;++j) G[i][j]=Gcd(i,j);
}
inline int gcd(int a, int b) {
    if(a <= 500 && b <= 500) return G[a][b];
    return b == 0 ? a : gcd(b, a % b);
}

unordered_map<int,ll> mp;
void cal(int u,int fa,int w) {
    for(auto p : mp) cnt[gcd(p.first, w)] += p.second;
    for(int v : g[u]) {
        if(v == fa || vis[v]) continue;
        cal(v, u, gcd(w, a[v]));
    }
}

void add(int u,int fa,int w) {
    mp[w]++;
    for(int v : g[u]) {
        if(v == fa || vis[v]) continue;
        add(v, u, gcd(w, a[v]));
    }
}
void calc(int u) {
    mp[a[u]]++;
    for(int v : g[u]) {
        if(vis[v]) continue;
        cal(v, u, gcd(a[u], a[v]));
        add(v, u, gcd(a[u], a[v]));
    }
    mp.clear();
}
void solve(int u) {
    vis[u] = 1; calc(u);
    for(int v : g[u]) {
        if(vis[v]) continue;
        N = sz[v]; rt = 0;
        getrt(v, u);
        solve(rt);
    }
}
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
int main() {
    init();
    int n = read();
    for(int i=1;i<=n;++i) a[i] = read(), cnt[a[i]]++;
    for(int i=1;i<n;++i) {
        int u = read(), v = read();
        g[u].push_back(v);
        g[v].push_back(u);
    }
    N = n; mx[0] = 1e9; rt = 0;
    getrt(1, -1);
    solve(rt);
    for(int i=1;i<maxn;++i) {
        if(cnt[i]) cout << i << " " << cnt[i] << endl;
    }
}