Count Prime-Valued Nodes in Subtree Queries

Given a tree rooted at node 0 with n nodes, each node has a positive integer value. Given q queries, each a node u, answer for each query how many nodes in the subtree of u (including u) have a prime ...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: