CF1817C.Similar Polynomials
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A polynomial A(x) of degree d is an expression of the form A(x)=a0+a1x+a2x2+⋯+adxd, where ai are integers, and ad=0. Two polynomials A(x) and B(x) are called similar if there is an integer s such that for any integer x it holds that
B(x)equivA(x+s)pmod109+7.
For two similar polynomials A(x) and B(x) of degree d, you're given their values in the points x=0,1,…,d modulo 109+7.
Find a value s such that B(x)≡A(x+s)(mod109+7) for all integers x.
一个次数为 d 的多项式 A(x) 是形如 A(x)=a0+a1x+a2x2+⋯+adxd 的表达式,其中 ai 为整数,且 ad=0。若存在整数 s,使得对任意整数 x 均满足
B(x)≡A(x+s)(mod109+7),
则称两个多项式 A(x) 和 B(x) 是相似的。
现给定两个次数均为 d 的相似多项式 A(x) 和 B(x) 在点 x=0,1,…,d 处的取值(模 109+7 意义下)。
请找出一个整数 s,使得对所有整数 x 均满足
B(x)≡A(x+s)(mod109+7).
输入格式
The first line contains a single integer d (1≤d≤2500000).
The second line contains d+1 integers A(0),A(1),…,A(d) (0≤A(i)<109+7) — the values of the polynomial A(x).
The third line contains d+1 integers B(0),B(1),…,B(d) (0≤B(i)<109+7) — the values of the polynomial B(x).
It is guaranteed that A(x) and B(x) are similar and that the leading coefficients (i.e., the coefficients in front of xd) of A(x) and B(x) are not divisible by 109+7.
第一行包含一个整数 d(1≤d≤2500000)。
第二行包含 d+1 个整数 A(0),A(1),…,A(d)(0≤A(i)<109+7)——多项式 A(x) 的值。
第三行包含 d+1 个整数 B(0),B(1),…,B(d)(0≤B(i)<109+7)——多项式 B(x) 的值。
保证 A(x) 与 B(x) 相似,且 A(x) 与 B(x) 的首项系数(即 xd 前的系数)均不能被 109+7 整除。
输出格式
Print a single integer s (0≤s<109+7) such that B(x)≡A(x+s)(mod109+7) for all integers x.
If there are multiple solutions, print any.
输出一个整数 s(0≤s<109+7),使得对所有整数 x,均有 B(x)≡A(x+s)(mod109+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) and B(x)≡x+2(mod109+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) and B(x)≡(x+10)2(mod109+7), hence $$B(x) \equiv A(x+9) \pmod{10^9+7}.$$
在第一个例子中,A(x)≡x−1(mod109+7) 且 B(x)≡x+2(mod109+7)。它们是相似的,因为
B(x)≡A(x+3)(mod109+7).
在第二个例子中,A(x)≡(x+1)2(mod109+7) 且 B(x)≡(x+10)2(mod109+7),因此
B(x)≡A(x+9)(mod109+7).
输入解题思路,AI测评打分。不知道怎么写?