Atenţie! Aceasta este o versiune veche a paginii, scrisă la 2022-11-15 18:48:36.
Revizia anterioară   Revizia următoare  

 

Fişierul intrare/ieşire:sumtree.in, sumtree.outSursăIIOT 2022-23 Runda I
AutorVlad-Mihai BogdanAdăugată deUnknownPercentageBuca Mihnea-Vicentiu UnknownPercentage
Timp execuţie pe test0.75 secLimită de memorie 262144 kbytes
Scorul tăuN/ADificultateN/A

Vezi solutiile trimise | Statistici

Sumtree

You are given a tree with N nodes. Each node has values assigned to it,  value_i . You must calculate the sum cost of every pair nodes (u, v), where gcd(value_u, value_v) > 1 and uv. For a pair of nodes [Unparseable or potentially dangerous LaTeX formula! Error 2 : def] (1 ≤ value_i ≤ 30000). Each of the next N - 1 lines will contain a pair of nodes (u, v), each representing an edge of the tree.

Date de ieşire

The output will contain the sum of costs over all pairs of nodes (u, v), such that gcd(value[u], value[v]) > 1

Restricţii

For the first subtask (1 ≤ N ≤ 1000)
For the second subtask,  value[i] = value[1] for i = 1, 2,...n

Exemplu

sumtree.insumtree.out
5
2 7 14 22 77
1 2
1 3
2 4
4 5
442
Trebuie sa te autentifici pentru a trimite solutii. Click aici

Cum se trimit solutii?