#P15053. [UOI 2023 II Stage] Land plots

    ID: 16983 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2023数论素数判断,质数,筛法UOI(乌克兰)

[UOI 2023 II Stage] Land plots

题目描述

Measuring a land plot is an important geodetic procedure. To obtain accurate numerical values, the measurement procedure should be performed by professional surveyors.

Let us consider the following problem. Let us assume that there is a square plot that surveyors have divided into n2n^2 rectangular plots by drawing (n1)(n-1) vertical and (n1)(n-1) horizontal lines. Let us number the rows and columns of the small plots as shown on the picture (the scale is not respected). That is, the rows are numbered from bottom to top by integer numbers from 11 to nn; and the columns are numbered from left to right by integer numbers from 11 to nn.

The plots located at the intersection of the ii-th column and the ii-th row (1in)(1 \le i \le n) will be called the "main diagonal". The plots located at the intersection of the (i+1)(i+1)-th column and the ii-th row (1in1)(1 \le i \le n-1) will be called the "side diagonal".

:::align{center} :::

You know the areas of the plots on the main and side diagonals. Calculate the area of the plot at the intersection of the pp-th column and the qq-th row.

输入格式

The first line contains an integer nn (2n10002 \le n \le 1\,000).

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \leq a_i \leq 10^9) --- the areas of the plots on the main diagonal.

The third line contains n1n-1 integers b1,b2,,bn1b_1, b_2, \dots, b_{n-1} (1bi1091 \leq b_i \leq 10^9) --- the areas of the plots on the side diagonal.

The fourth line contains two integers pp and qq (1p,qn1 \leq p, q \leq n) --- the coordinates of the plot, the area of which should be calculated.

输出格式

Output the area of the plot located at the intersection of the pp-th column and the qq-th row.

We want to know the exact value of the area, so the answer should be given in a factorized form. In other words, the answer should be represented as several lines, each containing two integers pip_i and sis_i: the number pip_i is necessarily prime, all pip_i are different, and the number sis_i is an integer and not equal to zero. The sought area must be equal to:

$$S = p_1^{s_1} \cdot p_2^{s_2} \cdot p_3^{s_3} \ldots p_k^{s_k},$$

where kk is the number of lines in the answer. The lines must be sorted in increasing order of prime numbers pip_i. Recall that a number XX is considered prime if it has exactly two positive integer divisors: 11 and XX.

If the required area is equal to 1, then output two units: <<1 1>>\texttt{<<1 1>>}.

5
6 1 3 9 5
3 9 3 6
2 3
3 -1
5
5 2 8 3 5
2 6 8 9
5 2
2 1
3 2
5
6 1 3 9 5
3 9 3 6
2 4
1 1

提示

The area on the left in the figure corresponds to the first test from the condition. The area of the plot at the intersection of the 2nd column and the 3rd row is equal to:

S=31=13 S = 3^{-1} = \frac{1}{3}

The area on the right in the figure corresponds to the second test from the condition. The area of the plot at the intersection of the 5th column and the 2nd row is equal to:

S=2132=18 S = 2^{1} \cdot 3^2 = 18

Scoring

  • (55 points): Areas of all known areas --- prime numbers up to 100100 or one. The area, the area of which must be calculated, is located on the main or side diagonal. (p1=qp - 1 = q or p=qp = q)
  • (55 points): Areas of all known areas --- prime numbers up to 100100 or one. The area whose area needs to be calculated is located at the intersection of the iith column and the (i+1)(i+1)th row. (p+1=qp + 1 = q)
  • (55 points): The areas of all known plots do not exceed 1000010\,000. The area, the area of which must be calculated, is located on the main or side diagonal. (p1=qp - 1 = q or p=qp = q)
  • (55 points): General restrictions on the area of all known plots. The area, the area of which must be calculated, is located on the main or side diagonal. (p1=qp - 1 = q or p=qp = q)
  • (55 points): The areas of all known plots do not exceed 1000010\,000. The area whose area needs to be calculated is located at the intersection of the iith column and the (i+1)(i+1)th row. (p+1=qp + 1 = q)
  • (55 points): General restrictions on the area of all known plots. The area whose area needs to be calculated is located at the intersection of the iith column and the (i+1)(i+1)th row. (p+1=qp + 1 = q)
  • (55 points): The number of plots is 2525 (n=5n = 5). The areas of all known plots do not exceed 100100.
  • (55 points): Areas of all known areas --- prime numbers up to 100100 or one. The area whose area needs to be calculated is in the upper left corner. (p=1p=1, q=nq=n)
  • (55 points): Areas of all known areas --- prime numbers up to 100100 or one. The area whose area needs to be calculated is in the lower right corner. (p=np=n, q=1q=1)
  • (55 points): Areas of all known areas --- prime numbers up to 100100 or one. The area, the area of which must be calculated, is located above the main diagonal. (p<qp < q)
  • (55 points): Areas of all known areas --- prime numbers up to 100100 or one. The area, the area of which must be calculated, is located under the main diagonal. (p>qp > q)
  • (55 points): The areas of all known plots do not exceed 100100. The area whose area needs to be calculated is in the upper left corner. (p=1p=1, q=nq=n)
  • (55 points): The areas of all known plots do not exceed 100100. The area whose area needs to be calculated is in the lower right corner. (p=np=n, q=1q=1)
  • (55 points): The areas of all known plots do not exceed 100100. The area, the area of which must be calculated, is located above the main diagonal. (p<qp < q)
  • (55 points): The areas of all known plots do not exceed 100100. The area, the area of which must be calculated, is located under the main diagonal. (p>qp > q)
  • (55 points): General restrictions on the area of all known plots. The area whose area needs to be calculated is in the upper left corner. (p=1p=1, q=nq=n)
  • (55 points): General restrictions on the area of all known plots. The area whose area needs to be calculated is in the lower right corner. (p=np=n, q=1q=1)
  • (88 points): General restrictions on the area of all known plots. The area, the area of which must be calculated, is located above the main diagonal. (p<qp < q)
  • (77 points): General restrictions on the area of all known plots. The area, the area of which must be calculated, is located under the main diagonal. (p>qp > q)