cswork / OAOpen practice workspace

MicrosoftOA #29

Great Subsequences

Estimated HardJudge-ready

Topics (AI-labelled)Bits & Math

A non-empty subsequence is good if the GCD of all its elements is greater than 1. Perform the point replacements one by one; after each one, take the number of good subsequences modulo 10⁹+7, and finally add these reduced counts together directly. The final sum is not taken modulo. Choices of different indices are counted separately.

Input

The first line contains N Q (1..100000), and the second line contains N values of A (1..100000); then Q lines X Y follow, with 1≤X≤N and 1≤Y≤100000.

Output

Output a single integer, the answer.

Example 1

Input:

2 1
1 2
1 2

Output:

3

Example 2

Input:

3 2
1 2 3
1 3
2 3

Output:

11

Example 3

Input:

5 2
2 2 2 2 2
1 1
2 1

Output:

22

Example notes

Example 1: the array becomes 2, 2; both single elements and the pair are valid, for 3 in total.

Example 2: after the two replacements there are 4 and 7 good subsequences respectively, for a sum of 11.

Example 3: the two replacements leave 4 copies of 2 and 3 copies of 2, giving 15 and 7 respectively, for a sum of 22.

Editorial

Loading solution…