QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#847. Game

统计

As everyone knows, Rikka is not very good at mathematics, so Yuta starts teaching her a game. Initially, there is an integer $x$. Each number has a "score" denoted by $f(x)$. The process proceeds as follows:

  1. Add $f(x)$ to the current score.
  2. If $x = 1$, the game ends.
  3. Otherwise, randomly choose a prime factor $p$ of $x$, and replace $x$ with $x/p$. Then return to step 1.

What is the expected total score? The answer should be modulo $P = 10^9 + 7$.

To train Rikka's calculation skills, Yuta wants her to answer his questions as quickly as possible. For each subsequent question, Yuta will modify the value of $f$ for a specific number. Of course, this problem is too difficult for the cute Rikka; can you help her?

Input

The first line contains two positive integers $x$ and $t$, representing the initial value and the number of questions (the initial $f$ values are also considered a question).

The next line contains $d(x)$ integers ($d(x)$ denotes the number of divisors of $x$), where the $i$-th number represents the score $f(v)$ for the $i$-th smallest divisor $v$ of $x$.

The next $t-1$ lines each contain two numbers $v$ and $y$, where $v|x$, indicating that $f(v)$ is updated to $y$. These modifications are cumulative (i.e., the changes are permanent).

Output

Output $t$ lines, representing the answer for each question (the initial $f$ values, and the state after each of the $t-1$ modifications).

Examples

Examples 1

6 1
1 2 4 8

Output 1

12

Note 1

In the first round, Rikka can divide 6 by 2 or 3, and in the next step, she will inevitably reach 1. Therefore, there are two equally probable processes: $6 \to 3 \to 1$ or $6 \to 2 \to 1$. The scores for these two processes are 13 and 11, respectively, so the expected value is 12.

Subtasks

For 100% of the data, $1\le x \le 10^{12}, 1\le t \le 3 \times 10^5, 1\le f(v),y \le 10^9$.

Test Case $x$ $t$ $x$ is a power of a prime
$1 \sim 2$ $\leq 20$ $\leq 1$
$3 \sim 4$ $\leq 10^9$
$5 \sim 6$ $\leq 10^6$
$7 \sim 8$ $\leq 10^3$
$9$ $\leq 10^{12}$
$10$
$11$ $\leq 10^9$ $\leq 5\,000$
$12$ $\leq 10^{12}$ $\leq 10^4$
$13$ $\leq 10^9$ $\leq 5 \times 10^4$
$14$ $\leq 10^5$
$15$ $\leq 3\times 10^5$
$16$
$17$ $\leq 10^{12}$ $\leq 10^4$
$18$ $\leq 5 \times 10^4$
$19$ $\leq 10^5$
$20$ $\leq 3 \times 10^5$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.