CF1725E.Electrical Efficiency

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

In the country of Dengkleknesia, there are NN factories numbered from 11 to NN . Factory ii has an electrical coefficient of AiA_i . There are also N1N-1 power lines with the jj -th power line connecting factory UjU_j and factory VjV_j . It can be guaranteed that each factory in Dengkleknesia is connected to all other factories in Dengkleknesia through one or more power lines. In other words, the collection of factories forms a tree. Each pair of different factories in Dengkleknesia can use one or more existing power lines to transfer electricity to each other. However, each power line needs to be turned on first so that electricity can pass through it.

Define f(x,y,z)f(x, y, z) as the minimum number of power lines that need to be turned on so that factory xx can make electrical transfers to factory yy and factory zz . Also define g(x,y,z)g(x, y, z) as the number of distinct prime factors of GCD(Ax,Ay,Az)\text{GCD}(A_x, A_y, A_z) .

To measure the electrical efficiency, you must find the sum of f(x,y,z)×g(x,y,z)f(x, y, z) \times g(x, y, z) for all combinations of (x,y,z)(x, y, z) such that 1x<y<zN1 \leq x < y < z \leq N . Because the answer can be very large, you just need to output the answer modulo 998244353998\,244\,353 .

Note: GCD(k1,k2,k3)\text{GCD}(k_1, k_2, k_3) is the greatest common divisor of k1k_1 , k2k_2 , and k3k_3 , which is the biggest integer that simultaneously divides k1k_1 , k2k_2 , and k3k_3 .

输入格式

The first line contains a single integer NN ( 1N21051 \le N \le 2 \cdot 10^5 ) — the number of factories in Dengkleknesia.

The second line contains NN integers A1,A2,,ANA_1, A_2, \dots, A_N ( 1Ai21051 \leq A_i \leq 2 \cdot 10^5 ) — the electrical coefficients of the factories.

The jj -th of the next N1N-1 lines contains two integers UjU_j and VjV_j ( 1Uj,VjN1 \le U_j, V_j \le N ) — a power line that connects cities UjU_j and VjV_j . The collection of factories forms a tree.

输出格式

An integer representing the sum of f(x,y,z)×g(x,y,z)f(x, y, z) \times g(x, y, z) for all combinations of (x,y,z)(x, y, z) such that 1x<y<zN1 \leq x < y < z \leq N , modulo 998244353998\,244\,353

输入输出样例

  • 输入#1

    3
    1 2 3
    1 2
    2 3

    输出#1

    0
  • 输入#2

    4
    6 14 6 6
    1 2
    2 3
    2 4

    输出#2

    12

说明/提示

In the first example, the only (x,y,z)(x, y, z) possible is (1,2,3)(1, 2, 3) . Because GCD(A1,A2,A3)=GCD(1,2,3)=1\text{GCD}(A_1, A_2, A_3) = \text{GCD}(1, 2, 3) = 1 has 00 distinct prime factors, therefore f(x,y,z)×g(x,y,z)=2×0=0f(x, y, z) \times g(x, y, z) = 2 \times 0 = 0 .

In the second example, all triples (x,y,z)(x, y, z) that satisfy the condition are as follows:

  • (1,2,3)f(1,2,3)×g(1,2,3)=2×1=2(1, 2, 3) \rightarrow f(1, 2, 3) \times g(1, 2, 3) = 2 \times 1 = 2
  • (1,2,4)f(1,2,4)×g(1,2,4)=2×1=2(1, 2, 4) \rightarrow f(1, 2, 4) \times g(1, 2, 4) = 2 \times 1 = 2
  • (1,3,4)f(1,3,4)×g(1,3,4)=3×2=6(1, 3, 4) \rightarrow f(1, 3, 4) \times g(1, 3, 4) = 3 \times 2 = 6
  • (2,3,4)f(2,3,4)×g(2,3,4)=2×1=2(2, 3, 4) \rightarrow f(2, 3, 4) \times g(2, 3, 4) = 2 \times 1 = 2

So the electrical efficiency is 2+2+6+2=122 + 2 + 6 + 2 = 12 .

首页