Trees and Primes

Given a tree on N vertices, find the probability that a uniformly random pair of distinct vertices has a prime distance.

Medium7TreeDFSNumber theoryDivide and conquerNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given a tree with NN vertices, numbered 1 through NN. The distance between two vertices is the number of edges on the path that joins them.

Two distinct vertices are chosen uniformly at random, so each of the (N2)\binom{N}{2} unordered pairs is equally likely. Write a program that computes the probability that the distance between the two chosen vertices is a prime number.

Input

The first line contains the number of vertices NN (2N500002 \le N \le 50000).

Each of the next N1N-1 lines contains the numbers uu and vv of two vertices joined by an edge, separated by a space (1u,vN1 \le u, v \le N, uvu \ne v).

The given graph is always a tree.

Output

Print the probability that the distance between the two chosen vertices is prime, with exactly 10 digits after the decimal point. Round half up at the eleventh digit and keep the trailing zeros. For example, if the probability is exactly 12\frac{1}{2}, print 0.5000000000.