#P5881. 【化学】实验

    ID: 4714 远端评测题 1400ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>图论并查集江苏O2优化素数判断,质数,筛法

【化学】实验

Description

In front of her, there are nn test tubes. Each test tube contains an unknown liquid. For each kind of unknown liquid, there are 22 known chemical attributes: aa and bb. The two attribute values of the ii-th liquid are aia_i and bib_i.

Now, the teacher assigns her mm experiments.

For each experiment, there is a reference value xx (the reference value of the ii-th experiment is denoted as xix_i). She needs to divide the unknown liquids into as many groups as possible, such that: for any two liquids ii and jj in different groups, gcsd(ai,aj)\operatorname{gcsd(a_i,a_j)} must not be greater than x2x^2.

Here, gcsd\operatorname{gcsd} denotes the greatest common square divisor. kk is a common square divisor of two numbers if and only if it satisfies both of the following:

  • kk is a common divisor of the two numbers;
  • kk is a perfect square.

The greatest common square divisor gcsd\operatorname{gcsd} is the maximum kk among all kk that satisfy the conditions.

Intuitively, gcsd\operatorname{gcsd} can be understood as: take the greatest common divisor of the two numbers, take its square root, keep only the integer factor part, and then square it back.

For example:

To compute gcsd(24,64)\operatorname{gcsd(24,64)}, first compute the greatest common divisor of 2424 and 6464, which is 88. Then 8=22\sqrt 8=2\sqrt 2. Its integer factor is 22, so gcsd(24,64)=22=4\operatorname{gcsd(24,64)}=2^2=4.

She also needs, under the condition that the number of groups is maximized, to maximize her experiment score.

Definition of the experiment score: for each reagent, define its score cic_i as the largest exponent in the prime factorization of bib_i.

For example: bi=12=22×31b_i=12=2^2\times 3^1, so ci=max{2,1}=2c_i=\max\{2,1\}=2.

bi=90=21×32×51b_i=90=2^1\times 3^2\times 5^1, so ci=max{1,2,1}=2c_i=\max\{1,2,1\}=2.

The experiment score is the sum, over all groups, of the maximum cic_i within each group.

Of course, her IQIQ is not very high, so she needs to ask for your help.

Input Format

The first line contains two integers n,mn,m.

The second line contains nn integers a1na_{1\dots n}.

The third line contains nn integers b1nb_{1\dots n}.

The fourth line contains mm integers x1mx_{1\dots m}.

Output Format

Output mm lines. For the ii-th line, output 22 integers: the number of groups and the experiment score for the ii-th experiment.

5 5
36 72 4 9 16
2 4 6 8 10
2 3 4 5 6

3 5
4 7
4 7
4 7
5 8

Hint

Sample Explanation #1

b1=2=21,c1=1b_1=2=2^1,c_1=1.

b2=4=22,c2=2b_2=4=2^2,c_2=2.

b3=6=21×31,c3=max{1,1}=1b_3=6=2^1\times 3^1,c_3=\max\{1,1\}=1.

b4=8=23,c4=3b_4=8=2^3,c_4=3.

b5=10=21×51,c5=max{1,1}=1b_5=10=2^1\times 5^1,c_5=\max\{1,1\}=1.

When x=2x=2, it can be divided into three groups: {1,2,4},{3},{5}\{1,2,4\},\{3\},\{5\}.

The experiment score is max{1,2,3}+max{1}+max{1}=5\max\{1,2,3\}+\max\{1\}+\max\{1\}=5.


Constraints

"This problem uses bundled testdata."

subtask nn\le mm\le aia_i \le bib_i\le xx \le Score
11 44 66 100100 4×1044 \times 10^4 100100 55
22 88 77 2020 10310^3 1010
33 2020 3030 5050 8×1038 \times 10^3 100100 1010
44 100100 6060 100100 4×1044 \times 10^4 10310^3
55 5×1035 \times 10^3 110110 10310^3 10510^5 4×1034 \times 10^3
66 2×1042 \times 10^4 250250 3×1033 \times 10^3 10610^6 3×1033 \times 10^3
77 5×104 5 \times 10^4 10310^3 10410^4 2×1072 \times 10^7 1.5×1041.5 \times 10^4 1515
88 10510^5 8×1038 \times 10^3 2×1042 \times 10^4 2.2×1042.2 \times 10^4
99 2×1052 \times 10^5 4×1044 \times 10^4 3×1043 \times 10^4 2020

For 100%100\% of the data:

1n,m2×1051 \le n,m \le 2\times 10^5, 2ai4×1042 \le a_i \le 4\times 10^4, 2bi2×1072 \le b_i \le 2\times 10^7, 2x3×1042 \le x \le 3\times 10^4.

I... I think I made a mistake again... Can I try one more time?

Translated by ChatGPT 5