CF986E.Prince's Problem
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let the main characters of this problem be personages from some recent movie. New Avengers seem to make a lot of buzz. I didn't watch any part of the franchise and don't know its heroes well, but it won't stop me from using them in this problem statement. So, Thanos and Dr. Strange are doing their superhero and supervillain stuff, but then suddenly they stumble across a regular competitive programming problem.
You are given a tree with n vertices.
In each vertex v there is positive integer av.
You have to answer q queries.
Each query has a from u v x.
You have to calculate ∏w∈Pgcd(x,aw)mod(109+7), where P is a set of vertices on path from u to v. In other words, you are to calculate the product of gcd(x,aw) for all vertices w on the path from u to v. As it might be large, compute it modulo 109+7. Here gcd(s,t) denotes the greatest common divisor of s and t.
Note that the numbers in vertices do not change after queries.
I suppose that you are more interested in superhero business of Thanos and Dr. Strange than in them solving the problem. So you are invited to solve this problem instead of them.
本题的主角来自某部近期上映的电影。新复仇者联盟似乎引起了广泛关注。我并未观看过该系列电影的任何一部,也不太了解其中的英雄人物,但这并不会妨碍我在本题题面中使用他们。于是,灭霸(Thanos)与奇异博士(Dr. Strange)正在各自履行超级英雄与超级反派的职责,却突然意外撞上了一道普通的算法竞赛题目。
给你一棵包含 n 个顶点的树。
每个顶点 v 上有一个正整数 av。
你需要回答 q 个询问。
每个询问形如 u v x。
你需要计算 ∏w∈Pgcd(x,aw)mod(109+7),其中 P 表示从顶点 u 到顶点 v 的路径上所有顶点构成的集合。换言之,你需要计算路径 u→v 上每个顶点 w 对应的 gcd(x,aw) 的乘积,并对 109+7 取模。此处 gcd(s,t) 表示 s 与 t 的最大公约数。
注意:顶点上的数值在所有询问过程中均不发生改变。
我们猜想,你可能更关心灭霸与奇异博士的超级英雄事务,而非他们解这道题的过程。因此,诚邀你代替他们来解决本题。
输入格式
In the first line of input there is one integer n (1≤n≤105) — the size of the tree.
In the next n−1 lines the edges of the tree are described. The i-th edge is described with two integers ui and vi (1≤ui,vi≤n) and it connects the vertices ui and vi. It is guaranteed that graph with these edges is a tree.
In the next line there are n integers a1,a2,…,an (1≤av≤107).
In the next line there is one integer q (1≤q≤105) — the number of queries.
And in the next q lines the queries are described. Each query is described with three integers ui, vi and xi (1≤ui,vi≤n, 1≤xi≤107).
输入的第一行包含一个整数 n(1≤n≤105)——树的大小。
接下来的 n−1 行描述了树的边。第 i 条边由两个整数 ui 和 vi(1≤ui,vi≤n)描述,表示连接顶点 ui 和 vi 的一条边。保证由这些边构成的图是一棵树。
接下来的一行包含 n 个整数 a1,a2,…,an(1≤av≤107)。
再下一行包含一个整数 q(1≤q≤105)——查询的数量。
接下来的 q 行描述了各个查询。每个查询由三个整数 ui、vi 和 xi(1≤ui,vi≤n,1≤xi≤107)描述。
输出格式
Print q numbers — the answers to the queries in the order they are given in the input. Print each answer modulo 109+7=1000000007. Print each number on a separate line.
输出 q 个数字——即按输入中给出的顺序对应的查询答案。每个答案需对 109+7=1000000007 取模。每个数字单独占一行。
输入输出样例
输入#1
4 1 2 1 3 1 4 6 4 9 5 3 2 3 6 2 3 2 3 4 7
输出#1
36 4 1
输入#2
6 1 2 2 3 2 4 1 5 5 6 100000 200000 500000 40000 800000 250000 3 3 5 10000000 6 2 3500000 4 1 64000
输出#2
196000 12250 999998215
输入解题思路,AI测评打分。不知道怎么写?