CF1817C.Similar Polynomials

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A polynomial A(x)A(x) of degree dd is an expression of the form A(x)=a0+a1x+a2x2+⋯+adxdA(x) = a_0 + a_1 x + a_2 x^2 + \dots + a_d x^d, where aia_i are integers, and ad≠0a_d \neq 0. Two polynomials A(x)A(x) and B(x)B(x) are called similar if there is an integer ss such that for any integer xx it holds that

B(x)equivA(x+s)pmod109+7.B(x) \\equiv A(x+s) \\pmod{10^9+7}.

For two similar polynomials A(x)A(x) and B(x)B(x) of degree dd, you're given their values in the points x=0,1,…,dx=0,1,\dots, d modulo 109+710^9+7.

Find a value ss such that B(x)≡A(x+s)(mod109+7)B(x) \equiv A(x+s) \pmod{10^9+7} for all integers xx.

一个次数为 dd 的多项式 A(x)A(x) 是形如 A(x)=a0+a1x+a2x2+⋯+adxdA(x) = a_0 + a_1 x + a_2 x^2 + \dots + a_d x^d 的表达式,其中 aia_i 为整数,且 ad≠0a_d \neq 0。若存在整数 ss,使得对任意整数 xx 均满足

B(x)≡A(x+s)(mod109+7),B(x) \equiv A(x+s) \pmod{10^9+7},

则称两个多项式 A(x)A(x) 和 B(x)B(x) 是相似的。

现给定两个次数均为 dd 的相似多项式 A(x)A(x) 和 B(x)B(x) 在点 x=0,1,…,dx = 0, 1, \dots, d 处的取值(模 109+710^9+7 意义下)。

请找出一个整数 ss,使得对所有整数 xx 均满足

B(x)≡A(x+s)(mod109+7).B(x) \equiv A(x+s) \pmod{10^9+7}.

输入格式

The first line contains a single integer dd (1≤d≤2 500 0001 \le d \le 2\,500\,000).

The second line contains d+1d+1 integers A(0),A(1),…,A(d)A(0), A(1), \ldots, A(d) (0≤A(i)<109+70 \le A(i) \lt 10^9+7) — the values of the polynomial A(x)A(x).

The third line contains d+1d+1 integers B(0),B(1),…,B(d)B(0), B(1), \ldots, B(d) (0≤B(i)<109+70 \le B(i) \lt 10^9+7) — the values of the polynomial B(x)B(x).

It is guaranteed that A(x)A(x) and B(x)B(x) are similar and that the leading coefficients (i.e., the coefficients in front of xdx^d) of A(x)A(x) and B(x)B(x) are not divisible by 109+710^9+7.

第一行包含一个整数 dd(1≤d≤2 500 0001 \le d \le 2\,500\,000)。

第二行包含 d+1d+1 个整数 A(0),A(1),…,A(d)A(0), A(1), \ldots, A(d)(0≤A(i)<109+70 \le A(i) \lt 10^9+7)——多项式 A(x)A(x) 的值。

第三行包含 d+1d+1 个整数 B(0),B(1),…,B(d)B(0), B(1), \ldots, B(d)(0≤B(i)<109+70 \le B(i) \lt 10^9+7)——多项式 B(x)B(x) 的值。

保证 A(x)A(x) 与 B(x)B(x) 相似,且 A(x)A(x) 与 B(x)B(x) 的首项系数(即 xdx^d 前的系数)均不能被 109+710^9+7 整除。

输出格式

Print a single integer ss (0≤s<109+70 \leq s \lt 10^9+7) such that B(x)≡A(x+s)(mod109+7)B(x) \equiv A(x+s) \pmod{10^9+7} for all integers xx.

If there are multiple solutions, print any.

输出一个整数 ss(0≤s<109+70 \leq s \lt 10^9+7),使得对所有整数 xx,均有 B(x)≡A(x+s)(mod109+7)B(x) \equiv A(x+s) \pmod{10^9+7}。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    1
    1000000006 0
    2 3

    输出#1

    3
  • 输入#2

    2
    1 4 9
    100 121 144

    输出#2

    9

说明/提示

In the first example, A(x)≡x−1(mod109+7)A(x) \equiv x-1 \pmod{10^9+7} and B(x)≡x+2(mod109+7)B(x)\equiv x+2 \pmod{10^9+7}. They're similar because $$B(x) \equiv A(x+3) \pmod{10^9+7}.$$

In the second example, A(x)≡(x+1)2(mod109+7)A(x) \equiv (x+1)^2 \pmod{10^9+7} and B(x)≡(x+10)2(mod109+7)B(x) \equiv (x+10)^2 \pmod{10^9+7}, hence $$B(x) \equiv A(x+9) \pmod{10^9+7}.$$

在第一个例子中,A(x)≡x−1(mod109+7)A(x) \equiv x-1 \pmod{10^9+7} 且 B(x)≡x+2(mod109+7)B(x)\equiv x+2 \pmod{10^9+7}。它们是相似的,因为

B(x)≡A(x+3)(mod109+7).B(x) \equiv A(x+3) \pmod{10^9+7}.

在第二个例子中,A(x)≡(x+1)2(mod109+7)A(x) \equiv (x+1)^2 \pmod{10^9+7} 且 B(x)≡(x+10)2(mod109+7)B(x) \equiv (x+10)^2 \pmod{10^9+7},因此

B(x)≡A(x+9)(mod109+7).B(x) \equiv A(x+9) \pmod{10^9+7}.

输入解题思路,AI测评打分。不知道怎么写?

首页