CF809E.Surprise me!

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Tired of boring dates, Leha and Noora decided to play a game.

Leha found a tree with nn vertices numbered from 11 to nn . We remind you that tree is an undirected graph without cycles. Each vertex vv of a tree has a number ava_{v} written on it. Quite by accident it turned out that all values written on vertices are distinct and are natural numbers between 11 and nn .

The game goes in the following way. Noora chooses some vertex uu of a tree uniformly at random and passes a move to Leha. Leha, in his turn, chooses (also uniformly at random) some vertex vv from remaining vertices of a tree (vu)(v≠u) . As you could guess there are n(n1)n(n-1) variants of choosing vertices by players. After that players calculate the value of a function f(u,v)=φ(auav)f(u,v)=φ(a_{u}·a_{v}) · d(u,v)d(u,v) of the chosen vertices where φ(x)φ(x) is Euler's totient function and d(x,y)d(x,y) is the shortest distance between vertices xx and yy in a tree.

Soon the game became boring for Noora, so Leha decided to defuse the situation and calculate expected value of function ff over all variants of choosing vertices uu and vv , hoping of at least somehow surprise the girl.

Leha asks for your help in calculating this expected value. Let this value be representable in the form of an irreducible fraction . To further surprise Noora, he wants to name her the value .

Help Leha!

输入格式

The first line of input contains one integer number nn (2<=n<=2105)(2<=n<=2·10^{5}) — number of vertices in a tree.

The second line contains nn different numbers a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ai<=n)(1<=a_{i}<=n) separated by spaces, denoting the values written on a tree vertices.

Each of the next n1n-1 lines contains two integer numbers xx and yy (1<=x,y<=n)(1<=x,y<=n) , describing the next edge of a tree. It is guaranteed that this set of edges describes a tree.

输出格式

In a single line print a number equal to PQ1P·Q^{-1} modulo 109+710^{9}+7 .

输入输出样例

  • 输入#1

    3
    1 2 3
    1 2
    2 3
    

    输出#1

    333333338
    
  • 输入#2

    5
    5 4 3 1 2
    3 5
    1 2
    4 3
    2 5
    

    输出#2

    8
    

说明/提示

Euler's totient function φ(n)φ(n) is the number of such ii that 1<=i<=n1<=i<=n ,and gcd(i,n)=1gcd(i,n)=1 , where gcd(x,y)gcd(x,y) is the greatest common divisor of numbers xx and yy .

There are 66 variants of choosing vertices by Leha and Noora in the first testcase:

  • u=1u=1 , v=2v=2 , f(1,2)=φ(a1a2)d(1,2)=φ(12)1=φ(2)=1f(1,2)=φ(a_{1}·a_{2})·d(1,2)=φ(1·2)·1=φ(2)=1
  • u=2u=2 , v=1v=1 , f(2,1)=f(1,2)=1f(2,1)=f(1,2)=1
  • u=1u=1 , v=3v=3 , f(1,3)=φ(a1a3)d(1,3)=φ(13)2=2φ(3)=4f(1,3)=φ(a_{1}·a_{3})·d(1,3)=φ(1·3)·2=2φ(3)=4
  • u=3u=3 , v=1v=1 , f(3,1)=f(1,3)=4f(3,1)=f(1,3)=4
  • u=2u=2 , v=3v=3 , f(2,3)=φ(a2a3)d(2,3)=φ(23)1=φ(6)=2f(2,3)=φ(a_{2}·a_{3})·d(2,3)=φ(2·3)·1=φ(6)=2
  • u=3u=3 , v=2v=2 , f(3,2)=f(2,3)=2f(3,2)=f(2,3)=2

Expected value equals to . The value Leha wants to name Noora is 731=7333333336=3333333387·3^{-1}=7·333333336=333333338 .

In the second testcase expected value equals to , so Leha will have to surprise Hoora by number 811=88·1^{-1}=8 .

首页