You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i.

Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to the simple path from vertex x to vertex y (including these two vertices). Also let's denote dist(x, y) as the number of vertices on the simple path between vertices x and y, including the endpoints. dist(x, x) = 1 for every vertex x.

Your task is calculate the maximum value of dist(x, y) among such pairs of vertices that g(x, y) > 1.

Input

The first line contains one integer n — the number of vertices (1 ≤ n ≤ 2 ⋅ 10^5).

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2 ⋅ 10^5) — the numbers written on vertices.

Then n - 1 lines follow, each containing two integers x and y (1 ≤ x, y ≤ n, x ≠ y) denoting an edge connecting vertex x with vertex y. It is guaranteed that these edges form a tree.

Output

If there is no pair of vertices x, y such that g(x, y) > 1, print 0. Otherwise print the maximum value of dist(x, y) among such pairs.

Examples

Input

3
2 3 4
1 2
2 3


Output

1


Input

3
2 3 4
1 3
2 3


Output

2


Input

3
1 1 1
1 2
2 3


Output

0
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class Task {

    public static void main(String[] args) throws IOException {

        new Task().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Task() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws IOException {

        int t = 1;
        while (t > 0) {
            solve();
            //out.println();
            t--;
        }

        out.flush();
        out.close();
    }

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    ArrayList<Integer>[] g;
    int[] a;

    void solve() throws IOException {

        int n = in.nextInt();
        a = new int[n];
        g = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            g[i] = new ArrayList<>();
            set[i] = new HashSet<>();
        }

        for (int i = 0; i < n - 1; i++) {
            int x = in.nextInt() - 1;
            int y = in.nextInt() - 1;
            g[x].add(y);
            g[y].add(x);
        }

        int[] p = new int[200001];
        int maxp = 200000;

        ArrayList<Integer>[] f = new ArrayList[maxp + 1];
        for (int i = 0; i <= maxp; i++)
            f[i] = new ArrayList<>();

        for (int i = 2; i <= Math.sqrt(maxp); i++) {
            if (p[i] == 0) {
                for (int j = i + i; j <= maxp; j += i) {
                    p[j] = 1;
                    f[j].add(i);
                }
            }
        }

        for (int i = 2; i < maxp; i++)
            if (p[i] == 0) f[i].add(i);

        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int prime : f[a[i]]) {
                if (!set[i].contains(prime)) {
                    dfs(i, -1, prime);
                    ans = Math.max(ans, max);
                }
            }
        }

        out.println(ans);
    }

    int max = 0;
    HashSet<Integer>[] set = new HashSet[200000];

    int dfs(int v, int p, int prime) {

        set[v].add(prime);
        int mx1 = 0;
        int mx2 = 0;

        for (int u : g[v]) {
            if (p != u && gcd(prime, a[u]) == prime) {
                int path = dfs(u, v, prime);
                if (path > mx1) {
                    mx2 = mx1;
                    mx1 = path;
                }
                else if (path > mx2) {
                    mx2 = path;
                }
            }
        }

        max = Math.max(max, mx1 + mx2 + 1);
        return mx1 + 1;
    }

    int gcd(int a, int b){
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;
        int i;

        Pair(int a, int b, int i) {
            this.a = a;
            this.b = b;
            this.i = i;
        }

        public int compareTo(Pair p) {
            if (a > p.a) return 1;
            if (a < p.a) return -1;
            if (b > p.b) return 1;
            if (b < p.b) return -1;
            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }


        String nextLine() throws IOException {
            return br.readLine();
        }

    }

}