#P6690. 一次函数

    ID: 7447 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP2020洛谷原创Special JudgeO2优化扩展欧几里德算法构造洛谷月赛

一次函数

Problem Description

You are given nn linear functions fi(x)=aix+bif_i(x) = a_i x + b_i, where xx is a placeholder of a formal power series.

Choose kk functions gi(x)g_i(x) from these nn functions (1ik1 \leq i \leq k). Define the set HH as the set of values obtained by taking a product of some powers of gig_i modulo x2x^2. That is:

$$H=\left\{\prod_{i=1}^k g_i(x)^j\bmod x^2\middle|0 \leq a, b < p \right\}$$

Here, jj can be any non-negative integer, and different ii may use different jj.

Note that 0x+10 \cdot x + 1 is always in the set HH (not 0x+00 \cdot x + 0). This is true even when k=0k = 0.

Given A,BA, B, find the minimum kk among all sets HH such that Ax+BHA x + B \in H.

If no such HH exists with Ax+BHA x + B \in H, output -1.

All operations are performed modulo pp.

Input Format

The first line contains four integers n,p,A,Bn, p, A, B.

The next nn lines each contain two integers ai,bia_i, b_i.

Output Format

The first line contains one integer kk, which is the answer.

If a solution exists, then the next kk lines each contain two integers a,ba, b, and they must satisfy:

(fa(x)b)modx2=Ax+B\left(\prod f_a(x)^b\right)\bmod x^2=Ax + B

The order of aa can be arbitrary.

1 997 603 648
200 61

1
1 140787

1 953 712 307
534 750

-1

3 7 6 5
3 4
5 6
4 6

2
2 5
1 20

Hint

There are also two large sample tests and a checker. The download link is in the attachments.

To test your answer for a certain test case, you need to run the following command in the command line under this problem directory:

<checker> <input‐file> <output‐file> <answer‐file> [<report‐file>]

Where:

  • <checker> is the executable file of the checker;
  • <input‐file> is the input file of that test case, such as func1.in;
  • <output‐file> is your output file for that test case, such as func1.out;
  • <answer‐file> is the answer file of that test case (you only need to provide the first line of the output), such as func1.ans;
  • <report‐file> is an optional parameter. If it is not given, the checker will output to the terminal; otherwise, it will output to that file, such as report1.txt.

Constraints: for all data, 2p1092\leq p\leq 10^9. It is guaranteed that pp is a prime. 1n5×1031\leq n \leq 5 \times 10^3, 0ai,A<p0\leq a_i, A < p, 1bi,B<p1\leq b_i, B < p.

The detailed constraints and notes are as follows (blank means the same as the constraints above):

Subtask ID Score nn pp Special Property
11 55 =1=1 1000\leq 1000
22 3\leq 3 =7=7
33 1515 100\leq 100 =31=31
44 2020 A=B=1A=B=1
55 2525 20\leq 20
66 1515 500\leq 500
77

Translated by ChatGPT 5