CF1817C.Similar Polynomials
普及/提高-
通过率:0%
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) \equiv A(x+s) \pmod{10^9+7}. $$ </p><p>For two similar polynomials $A(x)$ and $B(x)$ of degree $d$ , you're given their values in the points $x=0,1,\\dots, d$ modulo $10^9+7$ .</p><p>Find a value $s$ such that $B(x) \\equiv A(x+s) \\pmod{10^9+7}$ for all integers $x$$$.输入格式
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 .
输出格式
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.
输入输出样例
输入#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)equiv(x+1)2pmod109+7 and B(x)equiv(x+10)2pmod109+7 , hence $$ B(x) \equiv A(x+9) \pmod{10^9+7}. $$$$