#SP0000243. Yash và cây nguyên tố (Yash And Trees)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Yash và cây nguyên tố (Yash And Trees)
Yash And Trees
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a tree with vertices rooted at vertex . Each vertex holds a non-negative integer , and a positive integer is also given. The subtree of consists of and all its descendants under this rooting.
Process queries in order:
1 v x: increase by for every vertex in the subtree of .2 v: count the distinct primes for which there exists a vertex in the subtree of and a non-negative integer such that .
Each prime is counted only once even when several vertices witness it; is not prime. The tree topology never changes.
Input
- The first line contains .
- The second line contains exactly integers .
- Each of the next lines specifies an undirected tree edge .
- The next line contains integer .
- Each of the final lines contains
1 v xor2 v. Vertices are one-based. At least one query is of type2.
Output
For each 2 v query, print the number of distinct suitable primes on its own line. Type 1 queries produce no output.
Subtasks
-
Subtask 1 (20 points): ; ; ; a connected loop-free tree with edges; ; ; ; at least one type
2query. -
Subtask 2 (30 points): ; ; ; a connected loop-free tree with edges; ; ; ; at least one type
2query. -
Subtask 3 (50 points): ; ; ; a connected loop-free tree with edges; ; ; ; at least one type
2query.
Examples
Input
8 20
3 7 9 8 4 11 7 3
1 2
1 3
3 4
4 5
4 6
4 7
5 8
4
2 1
1 1 1
2 5
2 4
Output
3
1
1
Explanation
The primes below are . Query 2 1 checks all nodes and sees three distinct prime residues , so it prints 3. Operation 1 1 1 raises every value by , producing . The subtree of vertex contains vertices and with values , giving only residue : print 1. The subtree of vertex contains vertices with values , again giving only prime residue : print 1.